Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 68 lines (48 sloc) 1.35 KB
#!/usr/bin/env perl -s-
use strict;
use warnings;
use autodie;
use Email::Simple;
use File::HomeDir;
use File::Spec;
use Try::Tiny;
push @INC, File::Spec->catdir(File::HomeDir->my_home, 'bin', 'lib');
require PostRubric;
our $p;
my $queue = "/Users/rjbs/tmp/blog/";
unless ($p) { # new entry
my $fn = $queue . time . ".txt";
system("vi",'-S','~/.vim/blog.vim', $fn);
}
FILE: foreach my $file (glob("${queue}*")) {
unless ((stat $file)[7]) {
unlink $file or die "can't remove $file: $!";
print "removing empty $file\n";
next;
}
next FILE if $file =~ /^\./;
next FILE if $file =~ /\.posted$/;
next FILE unless -r $file;
my $entry_text = do { open my $in, '<', $file; local $/; <$in>; };
next FILE unless $entry_text;
my $errors;
my $entry = Email::Simple->new($entry_text);
my %document = map { $_ => scalar $entry->header($_) }
qw(title subtitle tags uri);
($document{body} = $entry->body);
unless ($document{tags} =~ /\@markup:md/) {
$document{body} =~ s/(?<![\t\n])\n(?![\t\n])/ /smg;
}
if ($entry->header('on-hold')) {
print "skipping message $file, on-hold header set\n";
next FILE;
}
try {
PostRubric->add_entry(\%document);
} catch {
warn "ERROR POSTING: $_";
$errors++;
};
if ($errors) { print "can't post $file now\n"; }
else { rename $file => "$file.posted"; }
}