sgregoratto.me

source files for www.sgregoratto.me
git clone git://git.sgregoratto.me/sgregoratto.me
Log | Files | Refs

new (1035B)


      1 #!/usr/bin/env perl
      2 use warnings;
      3 use strict;
      4 use utf8;
      5 use feature qw(say);
      6 use POSIX qw(strftime);
      7 use Lingua::EN::Titlecase::Simple 'titlecase';
      8 use XML::Writer;
      9 
     10 my $title;
     11 my $fname;
     12 my @time;
     13 my $isoTime = "%FT%TZ";
     14 my $fmtTime = "%B %e, %Y";
     15 my $postFile;
     16 my $xml;
     17 
     18 if (! @ARGV) {
     19 	die "usage: new title\n";
     20 }
     21 
     22 $title = $fname = join(" ", @ARGV);
     23 $title = titlecase($title);
     24 
     25 $fname =~ tr/A-Za-z0-9/-/cs;
     26 $fname =~ tr/A-Z/a-z/;
     27 $fname .= ".xml";
     28 
     29 open($postFile, '>', $fname)
     30 	or die "could not open $fname for reading\n";
     31 
     32 $xml = XML::Writer->new(OUTPUT => $postFile,
     33 			DATA_MODE => 1,
     34 			DATA_INDENT => 1);
     35 
     36 @time = localtime();
     37 $isoTime = strftime($isoTime, @time);
     38 $fmtTime = strftime($fmtTime, @time);
     39 $fmtTime =~ tr/ / /s;
     40 
     41 $xml->xmlDecl("utf-8");
     42 $xml->startTag("article", "data-sblg-article" => 1);
     43 	$xml->startTag("header");
     44 		$xml->dataElement("h1", $title);
     45 		$xml->dataElement("time", $fmtTime, "datetime" => $isoTime);
     46 	$xml->endTag("header");
     47 $xml->endTag("article");
     48 $xml->end();
     49 
     50 close($postFile);
     51 
     52 say $fname;