-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathblog
executable file
·67 lines (48 loc) · 1.35 KB
/
blog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/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"; }
}