X-Git-Url: https://git.shemshak.org/gitweb.cgi/~bandali/bndl.org/blobdiff_plain/d3adcff4a931922ad5ee52154cf78a7a339835cf..5d2cac6dd4039c174ab79f2cfd5c83ec1f3ac480:/txt2html?ds=sidebyside diff --git a/txt2html b/txt2html index 128995c..5b0acb8 100644 --- a/txt2html +++ b/txt2html @@ -23,6 +23,13 @@ use strict; use warnings 'all'; +use Getopt::Long; + +my $opt_lang = 'en'; +my $opt_index; +GetOptions ('lang=s' => \$opt_lang, + 'index' => \$opt_index) + or die("bad command line arguments\n"); my $link_re = qr{([\('!])?\b((?:ftps?|https?|nntps?|imaps?|s?news|gopher):// @@ -91,28 +98,39 @@ sub linkify { my $txt = do { local $/; <STDIN> }; my $title = html_esc($txt =~ /\A([^\n]+)/); $title =~ s/^\s+|\s+$//g; -if ($ARGV[0] and $ARGV[0] eq 'fa') { +if ($opt_lang eq 'fa') { $title .= ' — بÙدعÙÛ' if $title !~ /بÙدعÙÛ/; } else { $title .= ' — bandali' if $title !~ /bandali/; } +my ($url) = $txt =~ /(?:plain text|٠ت٠سادÙ): (.*)\r?\n?\z/; +$url = 'https://bndl.org/bandali-cv.txt' + if (!$url and $title =~ /curriculum vitae/); +$url = html_esc($url) if $url; $txt = linkify(html_esc($txt)); -print('<!doctype html>', - ($ARGV[0] and $ARGV[0] eq 'fa') - ? '<html lang="fa" dir="rtl">' - : '<html>', - '<head>', - '<meta -http-equiv="Content-Type" -content="text/html; charset=utf-8" -/>', - "<title>$title</title>", - ($ARGV[0] and $ARGV[0] eq 'fa') - ? "\n<style>\@font-face{font-family:sahel;font-weight:normal; +print("<!doctype html>", + qq(<html lang="$opt_lang"), + $opt_lang eq 'fa' ? ' dir="rtl"' : '', + ">", + qq(<head> +<meta http-equiv="Content-Type" +content="text/html; charset=utf-8" />\n), + "<title>$title</title>\n", + $url ? qq(<link rel="alternate" href="$url" +title="plain text" type="text/plain" />\n) : '', + ($opt_index and $opt_lang eq 'en') + ? qq(<link rel="alternate" href="https://bndl.org/fa/" +hreflang="fa" title="persian" />\n) + : ($opt_index and $opt_lang eq 'fa') + ? qq(<link rel="alternate" href="https://bndl.org/" +hreflang="en" title="english" />\n) + : '', + $opt_lang eq 'fa' + ? qq(<style>\@font-face{font-family:sahel;font-weight:normal; src:local('Sahel WOL'),local('Sahel'), -url('sahel.woff2')format('woff2');}pre{font-family:sahel}</style>\n" +url('sahel.woff2')format('woff2');}pre{font-family:sahel}</style>\n) : '', - '</head><body><pre>', $txt, '</pre></body></html>'); + "</head><body><pre>$txt</pre></body></html>\n"); STDOUT->flush;