add custom python3 'serve' script based on http.server
[~bandali/bndl.org] / txt2pre
diff --git a/txt2pre b/txt2pre
index 31fdb78..f25cbcf 100644 (file)
--- a/txt2pre
+++ b/txt2pre
@@ -1,8 +1,8 @@
 #!/usr/bin/env perl
-# txt2pre --- convert my site's txt files to `pre'-based html
+# txt2pre --- convert my site's txt files to `pre'-based atom/rss/html
 
 # Copyright (C) 2014-2021 all contributors <meta@public-inbox.org>
-# Copyright (c) 2021 Amin Bandali <bandali@gnu.org>
+# Copyright (c) 2021 bandali <bandali@gnu.org>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as
@@ -21,6 +21,9 @@
 # wonderful public-inbox project, under AGPLv3+, with additions of
 # my own.
 
+# Update (2021-11-01): this script isn't currently used for generating
+# my site's pages anymore; but kept for future reference.
+
 
 use strict;
 use warnings 'all';
@@ -195,11 +198,12 @@ my $txt = do { local $/; <STDIN> };
 
 my $title = html_esc($txt =~ /\A([^\n]+)/);
 $title =~ s/^\s+|\s+$//g;
-$title .= " &mdash; $author" if $title !~ /$author/;
+$title .= " &#8212; $author" if $title !~ /$author/;
 
 my ($upd, $pub, $url) = $txt =~ /(.*)\r?\n(.*)\r?\n(.*)\r?\n?\z/;
 ($upd) = $upd =~ /(?:updated|ویرایش): (.*)/ if $upd;
 ($pub) = $pub =~ /(?:published|انتشار): (.*)/ if $pub;
+$upd = $pub if (!$upd);
 ($url) = $url =~ /(?:plain text|متن ساده): (.*)/ if $url;
 $url = 'https://bndl.org/bandali-cv.txt'
     if (!$url and $title =~ /curriculum vitae/);
@@ -211,10 +215,10 @@ $txt = linkify(html_esc($txt));
 my $upd_iso8601 = `date -Iseconds -ud '$upd' | tr -d \\\\n` if $upd;
 my $pub_iso8601 = `date -Iseconds -ud '$pub' | tr -d \\\\n` if $pub;
 my $pub_rfc5322 = `date -uRd '$pub' | tr -d \\\\n` if $pub;
-my $url_html = $url =~ s/(?:[.]$lang)?[.]txt$/.html/r;
-$url_html =~ s|/bandali-(.*)|/$1|;
-my $slug = $url_html =~ s|.*/(.*)[.]html$|$1|r;
-my $note_id = "$feed_id:$slug";
+my $url_html = $url =~ s/(?:[.]$lang)?[.]txt$/.html/r if $url;
+$url_html =~ s|/bandali-(.*)|/$1| if $url_html;
+my $slug = $url_html =~ s|.*/(.*)[.]html$|$1|r if $url_html;
+my $note_id = "$feed_id:$slug" if $url_html;
 
 # note header
 if ($format eq 'html') {
@@ -272,7 +276,7 @@ qq(<link href="$url" rel="alternate" type="text/plain" />
 <link>$url_html</link>
 <guid isPermaLink="false">$note_id</guid>
 <pubDate>$pub_rfc5322</pubDate>\n)
-. ($updated ? $updated : '') .
+. (($updated and $pub ne $upd) ? $updated : '') .
 qq(<content:encoded><![CDATA[<pre>)
         : '';
 }