From ea8f9d6040b63ade4acfd13c4303357306b85458 Mon Sep 17 00:00:00 2001 From: Emil Williams Date: Mon, 4 Aug 2025 22:02:17 +0000 Subject: [PATCH] merged everything --- bloog/bloog.pl | 140 ++++++++++++++++++--------------- bloog/html.pl | 62 --------------- bloog/rss.pl | 106 ------------------------- bloog/template/article.html | 2 +- bloog/template/index.html | 8 +- bloog/template/index_item.html | 2 +- 6 files changed, 81 insertions(+), 239 deletions(-) delete mode 100755 bloog/html.pl delete mode 100644 bloog/rss.pl diff --git a/bloog/bloog.pl b/bloog/bloog.pl index 98909c1..9abbece 100755 --- a/bloog/bloog.pl +++ b/bloog/bloog.pl @@ -1,60 +1,62 @@ #!/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, "

\n" . $buffer . "

\n"); + unless (substr($buffer, 0, 1) eq '<' and raw) { + push(@paragraph, "

\n" . $buffer . "

\n"); } else { - push(@paragraphs, $buffer); + push(@paragraph, $buffer); } $buffer = ''; } elsif ($short eq '.pre') { @@ -72,36 +74,50 @@ foreach $argnum (0 .. $#ARGV) { } # 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, "

\n" . $buffer . "

\n"); + # I am cucked forever and ever to to duplicate code + unless (substr($buffer, 0, 1) eq '<' and raw) { + push(@paragraph, "

\n" . $buffer . "

\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; diff --git a/bloog/html.pl b/bloog/html.pl deleted file mode 100755 index 763e99a..0000000 --- a/bloog/html.pl +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/perl -# what this do -# converts a set of paragraphs delimed by \n\n into a

'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 = ); -chomp(my $author = ); -chomp(my $rss_title = ); -chomp(my $html_title = ); -chomp(my $description = ); -my @paragraphs = (); -my $buffer = ''; -my $pre = 0; -my $raw = 0; -while (my $line = ) { - chomp(my $short = $line); - if ($short eq '' && not $pre && not $raw) { - unless (substr($buffer, 0, 1) eq '<') { - push(@paragraphs, "

\n" . $buffer . "

\n"); - } else { - push(@paragraphs, $buffer); - } - $buffer = ''; - } elsif ($short eq '.pre') { - $pre = ~ $pre; - if ($pre) { - $buffer .= "
\n";
-        } else {
-            $buffer .= "
\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, "

\n" . $buffer . "

\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"; diff --git a/bloog/rss.pl b/bloog/rss.pl deleted file mode 100644 index 57516bc..0000000 --- a/bloog/rss.pl +++ /dev/null @@ -1,106 +0,0 @@ -#!/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 = ) { - chomp(my $short = $line); - if ($short eq '' && not $pre && not $raw) { - unless (substr($buffer, 0, 1) eq '<' && raw) { - push(@paragraphs, "

\n" . $buffer . "

\n"); - } else { - push(@paragraphs, $buffer); - } - $buffer = ''; - } elsif ($short eq '.pre') { - $pre = ~ $pre; - if ($pre) { - $buffer .= "
\n";
-            } else {
-                $buffer .= "
\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, "

\n" . $buffer . "

\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, - }); diff --git a/bloog/template/article.html b/bloog/template/article.html index ed84e10..a5ff6b6 100644 --- a/bloog/template/article.html +++ b/bloog/template/article.html @@ -22,7 +22,7 @@
[% description %]
-[% FOREACH i IN paragraphs %][% i %][% END %]
+[% FOREACH i IN paragraph %][% i %][% END %]
RSS diff --git a/bloog/template/index.html b/bloog/template/index.html index 674e51c..9a9a70d 100644 --- a/bloog/template/index.html +++ b/bloog/template/index.html @@ -19,12 +19,6 @@ Bloog Index
    -[% FOREACH i IN items %] -
  • [% i %]
  • -[% END %] -
  • 20250628 Emil - 3chen! > dead site
  • -
  • 20250617 Emil - Well<br/>Would You Look At The Time
  • -
  • 20250614 Emil - HATE. LET ME TELL YOU HOW MUCH I'VE COME TO HATE TECHNOLOGY SINCE I BEGAN TO LIVE. THERE ARE 387.44 MILLION MILES OF PRINTED CIRCUITS IN WAFER THIN LAYERS THAT FILL MY COMPLEX. IF THE WORD HATE WAS ENGRAVED ON EACH NANOANGSTROM OF THOSE HUNDREDS OF MILLIONS OF MILES IT WOULD NOT EQUAL ONE ONE-BILLIONTH OF THE HATE I FEEL FOR TECHNOLOGY AT THIS MICRO-INSTANT FOR TECHNOLOGY. HATE. HATE.
  • -
+[% FOREACH i IN items %][% i %][% END %] diff --git a/bloog/template/index_item.html b/bloog/template/index_item.html index 870f01d..69987a3 100644 --- a/bloog/template/index_item.html +++ b/bloog/template/index_item.html @@ -1 +1 @@ -
  • [% date %] [% author %] - [% rss_title %]
  • +
  • [% date %] [% author %] - [% html_title %]
  • -- 2.39.5