#!/usr/bin/perl -w # # Automate blog posting procedure die "Usage: post.pl \n" unless scalar @ARGV == 1; my $draft = shift; my $post = ""; my $tagsdir = "/home/adotti/devel/blog/html/tag"; my $tagext = "mdwn"; my $iconsdir = "/home/adotti/devel/blog/html/icons"; my $iconext = "png"; my $postsdir = "/home/adotti/devel/blog/html/post"; open (DRAFT, "$draft") or die "Can't open draft: $!\n"; ($post = $draft) =~ s|.+/||; open (POST, ">$postsdir/$post") or die "Can't open post: $!\n"; # Tag the post # my @tagfiles = glob("$tagsdir/*.$tagext"); my $idx = 0; my @tags = (); foreach my $tag (@tagfiles) { next unless $tag =~ m|^/(.+)?/(.+)\..+$|; $tags[$idx] = $2; printf ("%2s: %s\n", $idx, $2); $idx++; } print "\n"; print "Choose a list of tags (space separated): "; my $choosen_tags = <>; my @choosen_tags = split /\s/, $choosen_tags; print POST "[[tag "; foreach my $tag (@choosen_tags) { print POST "$tags[$tag] "; } print POST "]]\n"; # Choose an icon # my @iconfiles = glob("$iconsdir/*.$iconext"); $idx = 0; my @icons = (); foreach my $icon (@iconfiles) { next unless $icon =~ m|^/(.+)?/(.+)\..+$|; $icons[$idx] = $2; printf ("%2s: %s\n", $idx, $2); $idx++; } print "\n"; print "Choose an icon: "; my $choosen_icon = <>; print POST "\"$icons[$choosen_icon]\"\n"; print POST ; close DRAFT; close POST;