Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 58 lines (45 sloc) 1.29 KB
#!/usr/bin/perl
# newpost
use strict;
use Carp;
use Data::Dumper;
chomp(my $date = `date +%Y-%m-%d`);
my $dir = "$ENV{HOME}/devel/trapd00r.se/all";
my @categories = grep{!/_site/} glob("$dir/*");
print "Categories available:\n";
print "$_\n" for basename(@categories); # os,perl,sex
print "Category: ";
chomp(my $newpostcat = <STDIN>);
print "\n";
print "Available posts in $newpostcat:\n";
my @postsincat = glob("$dir/$newpostcat/_posts/*");
print "$_\n" for basename(@postsincat);
print "\n\n";
print "New post: ";
chomp(my $newpostname = <STDIN>);
unless($newpostname eq "" or !$newpostname) {
newpost($newpostname);
}
sub newpost {
my $title = shift;
my $filename = $title;
$filename =~ s/\s/-/g;
$filename =~ s/-{1,}/-/g;
my $fullpath = "$dir/$newpostcat/_posts/$date-$filename";
open(my $fh, '>>', "$fullpath.textile")
or croak "Cant open $fullpath.textile : $!";
chomp(my $friendlydate = `date '+%d %B %Y'`);
print $fh "---\nlayout: post\ntitle: \"$title\"\n---\n\n";
print $fh "h2. {{ page.title }}\n\n";
print $fh "p(publish_date). $friendlydate\n\n<p>\n";
print $fh "# vim: ft=html textwidth=120 nowrap:\n\n";
close $fh;
system("vim", "$fullpath.textile");
}
sub basename {
my @cat = @_;
for my $cat(@cat) {
$cat =~ s/.+\/(.+$)/$1/;
}
return @cat;
}