sgregoratto.me

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

new (1037B)


      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 die "usage: new title\n" if not @ARGV or $ARGV[0] eq "-h";
     19 
     20 $title = $fname = join(" ", @ARGV);
     21 $title = titlecase($title);
     22 
     23 $fname =~ tr/A-Za-z0-9/-/cs;
     24 $fname =~ tr/A-Z/a-z/;
     25 $fname .= ".xml";
     26 
     27 open($postFile, '>', $fname) or die "could not open $fname\n";
     28 
     29 $xml = XML::Writer->new(OUTPUT => $postFile,
     30 			DATA_MODE => 1,
     31 			DATA_INDENT => 1);
     32 
     33 @time = localtime();
     34 $isoTime = strftime($isoTime, @time);
     35 $fmtTime = strftime($fmtTime, @time);
     36 $fmtTime =~ tr/ / /s;
     37 
     38 $xml->xmlDecl("utf-8");
     39 $xml->startTag("article", "data-sblg-article" => 1);
     40 	$xml->startTag("header");
     41 		$xml->dataElement("h1", $title);
     42 		$xml->dataElement("time", $fmtTime, "datetime" => $isoTime);
     43 	$xml->endTag("header");
     44 $xml->endTag("article");
     45 $xml->end();
     46 
     47 close($postFile);
     48 
     49 say $fname;