From: Amin Bandali Date: Sun, 10 Oct 2021 02:08:37 +0000 (-0400) Subject: txt2html: use Getopt::Long for saner command line arg handling X-Git-Url: https://git.shemshak.org/~bandali/bndl.org/commitdiff_plain/e02deb23bf382d706e4085467fc0eb2b5b7364c0 txt2html: use Getopt::Long for saner command line arg handling --- diff --git a/GNUmakefile b/GNUmakefile index 2330e5d..f5b4014 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -9,7 +9,7 @@ gen = perl txt2html < $< > $@ -gen_fa = perl txt2html 'fa' < $< > $@ +gen_fa = perl txt2html --lang='fa' < $< > $@ port := $(if $(port),$(port),8000) TXT := $(filter-out bandali-pubkey.txt bandali.txt,$(wildcard *.txt)) diff --git a/txt2html b/txt2html index 128995c..f2a23d9 100644 --- a/txt2html +++ b/txt2html @@ -23,6 +23,11 @@ use strict; use warnings 'all'; +use Getopt::Long; + +my $opt_lang = 'en'; +GetOptions ('lang=s' => \$opt_lang) + or die("bad command line arguments\n"); my $link_re = qr{([\('!])?\b((?:ftps?|https?|nntps?|imaps?|s?news|gopher):// @@ -91,7 +96,7 @@ sub linkify { my $txt = do { local $/; }; 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/; @@ -100,16 +105,14 @@ if ($ARGV[0] and $ARGV[0] eq 'fa') { $txt = linkify(html_esc($txt)); print('', - ($ARGV[0] and $ARGV[0] eq 'fa') - ? '' - : '', - '', - '', + '', "$title", - ($ARGV[0] and $ARGV[0] eq 'fa') + $opt_lang eq 'fa' ? "\n\n"