#!/bin/perl
# everything generator
-# remember to put the last one chronologically at the end of the ARGV list
use Template;
use Time::Piece;
use POSIX qw(strftime);
+my $outdir = 'out/';
+
my $template = Template->new({
INCLUDE_PATH => 'template',
INTERPOLATE => 1,
}) || die "$Template::ERROR\n";
-my @rss_items = ();
-my @index_items = ();
-my $last_time = '';
-my $fh;
+sub template_write {
+ my $content = '';
+ $template->process($_[0], $_[2], \$content)
+ || die $template->error(), "\n";
+ open(my $fh, '>', $_[1]) or die $!;
+ print $fh $content;
+ close $fh;
+}
-foreach $argnum (0 .. $#ARGV) {
- open($fh, '<', $ARGV[$argnum]) or die $!;
- # general data
- chomp(my $date = <$fh>);
- chomp(my $author = <$fh>);
- chomp(my $rss_title = <$fh>);
- chomp(my $html_title = <$fh>);
- chomp(my $description = <$fh>);
- my $pubdate = Time::Piece->strptime($date, '%Y%m%d')->strftime("%a, %d %b %Y %H:%M:%S %z");
- $last_time = $pubdate; # this doesn't actually do any chronology
- my $data = {
- date => $date,
- pubdate => $pubdate,
- author => $author,
- rss_title => $rss_title,
- rss_title => $html_title,
- description => $description,
- };
+sub bloog {
+ my %d;
+ open(my $fh, '<', $_[0]) or die $!;
+ chomp($d{'date'} = <$fh>);
+ chomp($d{'author'} = <$fh>);
+ chomp($d{'rss_title'} = <$fh>);
+ chomp($d{'html_title'} = <$fh>);
+ chomp($d{'description'} = <$fh>);
+ $d{'pubdate'} = Time::Piece->strptime($d{'date'}, '%Y%m%d')->strftime("%a, %d %b %Y %H:%M:%S %z");
+ return (\%d, $fh);
+}
+
+sub arrayify {
+ my ($name, $dref, $pushref) = @_;
+ %d = %$dref;
+ @push = @{$pushref};
my $buffer = '';
- # rss item
- $template->process('feed_item.xml', $data, \$buffer)
+ $template->process($name, \%d, \$buffer)
|| die $template->error(), "\n";
- push(@rss_items, $buffer);
- $buffer = '';
- # index item
- $template->process('index_item.html', $data, \$buffer)
- || die $template->error(), "\n";
- push(@index_items, $buffer);
- # article
- $buffer = '';
- my @paragraphs = ();
+ push(@push, $buffer);
+ return \@push;
+}
+
+sub html_write {
+ my ($dref, $fh) = @_;
+ %d = %$dref;
+ my @paragraph;
+ my $buffer = '';
my $pre = 0;
my $raw = 0;
while (my $line = <$fh>) {
chomp(my $short = $line);
if ($short eq '' && not $pre && not $raw) {
- unless (substr($buffer, 0, 1) eq '<' && raw) {
- push(@paragraphs, "<p>\n" . $buffer . "</p>\n");
+ unless (substr($buffer, 0, 1) eq '<' and raw) {
+ push(@paragraph, "<p>\n" . $buffer . "</p>\n");
} else {
- push(@paragraphs, $buffer);
+ push(@paragraph, $buffer);
}
$buffer = '';
} elsif ($short eq '.pre') {
}
# I dare not use a function
# I dare not use a goto (deprecated in 5.42, fuck you too)
- # I am cucked forever to duplicate code
- unless (substr($buffer, 0, 1) eq '<' && raw) {
- push(@paragraphs, "<p>\n" . $buffer . "</p>\n");
+ # I am cucked forever and ever to to duplicate code
+ unless (substr($buffer, 0, 1) eq '<' and raw) {
+ push(@paragraph, "<p>\n" . $buffer . "</p>\n");
} else {
- push(@paragraphs, $buffer);
+ push(@paragraph, $buffer);
}
- my $article;
- $data{paragraphs} = \@paragraphs;
- $template->process('article.html', $data, \$article)
- || die $template->error(), "\n";
- close $fh;
- open($fh, '>', 'out/' . $date . '.html') or die $!;
- print $fh $article;
- close $fh;
-}
-sub template_write {
+ $d{'paragraph'} = \@paragraph;
my $content;
- $template->process($_[0], $_[2], \$content)
+ $template->process('article.html', \%d, \$content)
|| die $template->error(), "\n";
- open(my $fh, '>', $_[1]) or die $!;
- print $fh $content;
- close $fh;
+ open(my $out, '>', $outdir . $d{'date'} . '.html') or die $!;
+ print $out $content;
+ close($out);
}
-template_write('index.html', 'out/bloog.html', {
- items => \@index_items,
- });
+sub main {
+ my @rss_items = ();
+ my @index_items = ();
+ my $last_time = '';
+
+ foreach $argnum (0 .. $#ARGV) {
+ # general data
+ my ($dref, $fh) = bloog($ARGV[$argnum]);
+ my %d = %$dref;
+ if ((($d{'pubdate'} cmp $last_time) == 1) && ($last_time eq '')) {
+ $last_time = $d{'pubdate'}
+ }
+ # rss & index
+ @rss_items = @{arrayify('feed_item.xml', \%d, \@rss_items)};
+ @index_items = @{arrayify('index_item.html', \%d, \@index_items)};
+ # html page
+ html_write(\%d, $fh);
+ close($fh);
+ }
+
+ template_write('feed.xml', $outdir . 'feed.xml', {
+ items => \@rss_items,
+ last_time => $last_time,
+ });
+
+ template_write('index.html', $outdir . 'bloog.html', {
+ items => \@index_items,
+ });
+}
-template_write('feed.xml', 'out/feed.xml', {
- items => \@rss_items,
- last_time => $last_time,
- });
+main;
+++ /dev/null
-#!/bin/perl
-# what this do
-# converts a set of paragraphs delimed by \n\n into a <p></p>'d article.
-# ignores .pre until .pre, ignores .raw until .raw
-use Template;
-
-my $template = Template->new({
- INTERPOLATE => 1,
- }) || die "$Template::ERROR\n";
-
-chomp(my $date = <STDIN>);
-chomp(my $author = <STDIN>);
-chomp(my $rss_title = <STDIN>);
-chomp(my $html_title = <STDIN>);
-chomp(my $description = <STDIN>);
-my @paragraphs = ();
-my $buffer = '';
-my $pre = 0;
-my $raw = 0;
-while (my $line = <STDIN>) {
- chomp(my $short = $line);
- if ($short eq '' && not $pre && not $raw) {
- unless (substr($buffer, 0, 1) eq '<') {
- push(@paragraphs, "<p>\n" . $buffer . "</p>\n");
- } else {
- push(@paragraphs, $buffer);
- }
- $buffer = '';
- } elsif ($short eq '.pre') {
- $pre = ~ $pre;
- if ($pre) {
- $buffer .= "<pre>\n";
- } else {
- $buffer .= "</pre>\n";
- }
- } elsif ($short eq '.raw') {
- $raw = ~ $raw;
- } else {
- $buffer .= $line;
- }
-}
-# I dare not use a function
-# I dare not use a goto (deprecated in 5.42, fuck you too)
-# I am cucked forever and ever to to duplicate code
-unless (substr($buffer, 0, 1) eq '<') {
- push(@paragraphs, "<p>\n" . $buffer . "</p>\n");
-} else {
- push(@paragraphs, $buffer);
-}
-
-
-my $data = {
- rss_title => $rss_title,
- html_title => $html_title,
- author => $author,
- date => $date,
- description => $description,
- paragraphs => \@paragraphs,
-};
-
-$template->process('template.html', $data)
- || die $template->error(), "\n";
+++ /dev/null
-#!/bin/perl
-# everything generator
-# remember to put the last one chronologically at the end of the ARGV list
-use Template;
-use Time::Piece;
-use POSIX qw(strftime);
-
-my $template = Template->new({
- INCLUDE_PATH => 'template',
- INTERPOLATE => 1,
- }) || die "$Template::ERROR\n";
-
-my @rss_items = ();
-my @index_items = ();
-my $last_time = '';
-my $fh;
-
-foreach $argnum (0 .. $#ARGV) {
- my $buffer;
- open($fh, '<', $ARGV[$argnum]) or die $!;
- # general data
- chomp(my $date = <$fh>);
- chomp(my $author = <$fh>);
- chomp(my $rss_title = <$fh>);
- chomp(my $html_title = <$fh>);
- chomp(my $description = <$fh>);
- my $pubdate = Time::Piece->strptime($date, '%Y%m%d')->strftime("%a, %d %b %Y %H:%M:%S %z");
- $last_time = $pubdate; # this doesn't actually do any chronology
- my $data = {
- date => $date,
- pubdate => $pubdate,
- author => $author,
- rss_title => $rss_title,
- rss_title => $html_title,
- description => $description,
- };
- # rss item
- $template->process('feed_item.xml', $data, \$buffer)
- || die $template->error(), "\n";
- push(@rss_items, $buffer);
- # index item
- $template->process('index_item.html', $data, \$buffer)
- || die $template->error(), "\n";
- push(@index_items, $buffer);
- # article
- $buffer = '';
- my @paragraphs = ();
- my $pre = 0;
- my $raw = 0;
- while (my $line = <STDIN>) {
- chomp(my $short = $line);
- if ($short eq '' && not $pre && not $raw) {
- unless (substr($buffer, 0, 1) eq '<' && raw) {
- push(@paragraphs, "<p>\n" . $buffer . "</p>\n");
- } else {
- push(@paragraphs, $buffer);
- }
- $buffer = '';
- } elsif ($short eq '.pre') {
- $pre = ~ $pre;
- if ($pre) {
- $buffer .= "<pre>\n";
- } else {
- $buffer .= "</pre>\n";
- }
- } elsif ($short eq '.raw') {
- $raw = ~ $raw;
- } else {
- $buffer .= $line;
- }
- }
- # I dare not use a function
- # I dare not use a goto (deprecated in 5.42, fuck you too)
- # I am cucked forever to duplicate code
- unless (substr($buffer, 0, 1) eq '<' && raw) {
- push(@paragraphs, "<p>\n" . $buffer . "</p>\n");
- } else {
- push(@paragraphs, $buffer);
- }
- my $article;
- $data->paragraphs = \@paragraphs;
- $template->process('article.html', $data, \$article)
- || die $template->error(), "\n";
- close $fh;
- open($fh, '>', 'out/' . $date . '.html') or die $!;
- print $fh $article;
- close $fh;
-}
-
-sub template_write {
- my $content;
- $template->process($_[0], $_[2], \$content)
- || die $template->error(), "\n";
- open(my $fh, '>', $_[1]) or die $!;
- print $fh $content;
- close $fh;
-}
-
-template_write('index.html', 'out/bloog.html', {
- items => \@index_items,
- });
-
-template_write('feed.xml', 'out/feed.xml', {
- items => \@rss_items,
- last_time => $last_time,
- });