From b1f32cc6ca9f1bcdba656157c4f1d11911d26d08 Mon Sep 17 00:00:00 2001 From: Emil Williams Date: Mon, 4 Aug 2025 15:26:53 +0000 Subject: [PATCH] sneed --- bloog/bloog.pl | 106 ++++++++++++++++++ bloog/html.pl | 1 - bloog/rss.pl | 90 ++++++++++++--- .../{template.html => template/article.html} | 0 bloog/{template.xml => template/feed.xml} | 0 .../feed_item.xml} | 0 bloog/template/index.html | 30 +++++ bloog/template/index_item.html | 1 + 8 files changed, 213 insertions(+), 15 deletions(-) create mode 100755 bloog/bloog.pl mode change 100755 => 100644 bloog/rss.pl rename bloog/{template.html => template/article.html} (100%) rename bloog/{template.xml => template/feed.xml} (100%) rename bloog/{template_item.xml => template/feed_item.xml} (100%) create mode 100644 bloog/template/index.html create mode 100644 bloog/template/index_item.html diff --git a/bloog/bloog.pl b/bloog/bloog.pl new file mode 100755 index 0000000..aedae3f --- /dev/null +++ b/bloog/bloog.pl @@ -0,0 +1,106 @@ +#!/bin/perl +# feed.xml generator +# remember to put the last 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/html.pl b/bloog/html.pl index 92a1eea..763e99a 100755 --- a/bloog/html.pl +++ b/bloog/html.pl @@ -3,7 +3,6 @@ # converts a set of paragraphs delimed by \n\n into a

'd article. # ignores .pre until .pre, ignores .raw until .raw use Template; -use feature "switch"; my $template = Template->new({ INTERPOLATE => 1, diff --git a/bloog/rss.pl b/bloog/rss.pl old mode 100755 new mode 100644 index a380bc0..57516bc --- a/bloog/rss.pl +++ b/bloog/rss.pl @@ -1,25 +1,28 @@ #!/bin/perl -# feed.xml generator -# remember to put the last chronologically at the end of the ARGV list +# 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 @items = (); +my @rss_items = (); +my @index_items = (); my $last_time = ''; +my $fh; foreach $argnum (0 .. $#ARGV) { my $buffer; - open(my $fh, '<', $ARGV[$argnum]) or die "Can't open $filename: $!"; + open($fh, '<', $ARGV[$argnum]) or die $!; + # general data chomp(my $date = <$fh>); - chomp(my $author = <$fh>); chomp(my $rss_title = <$fh>); - $_ = <$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 @@ -28,17 +31,76 @@ foreach $argnum (0 .. $#ARGV) { pubdate => $pubdate, author => $author, rss_title => $rss_title, + rss_title => $html_title, description => $description, }; - $template->process('template_item.xml', $data, \$buffer) + # rss item + $template->process('feed_item.xml', $data, \$buffer) || die $template->error(), "\n"; - push(@items, $buffer); + 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; } -my $data = { - items => \@items, - last_time => $last_time, -}; +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->process('template.xml', $data) - || die $template->error(), "\n"; +template_write('feed.xml', 'out/feed.xml', { + items => \@rss_items, + last_time => $last_time, + }); diff --git a/bloog/template.html b/bloog/template/article.html similarity index 100% rename from bloog/template.html rename to bloog/template/article.html diff --git a/bloog/template.xml b/bloog/template/feed.xml similarity index 100% rename from bloog/template.xml rename to bloog/template/feed.xml diff --git a/bloog/template_item.xml b/bloog/template/feed_item.xml similarity index 100% rename from bloog/template_item.xml rename to bloog/template/feed_item.xml diff --git a/bloog/template/index.html b/bloog/template/index.html new file mode 100644 index 0000000..674e51c --- /dev/null +++ b/bloog/template/index.html @@ -0,0 +1,30 @@ + + + + + + + + +Bloog Index + + +
+< Back +
+Bloog Index +
+ + RSS + +
+
    +[% 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.
  • +
+ + diff --git a/bloog/template/index_item.html b/bloog/template/index_item.html new file mode 100644 index 0000000..870f01d --- /dev/null +++ b/bloog/template/index_item.html @@ -0,0 +1 @@ +
  • [% date %] [% author %] - [% rss_title %]
  • -- 2.39.5