2 # Copyright (C) 2014-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 # Stupid script to make HTML from preformatted, utf-8 text versions,
6 # only generating links for http(s). Markdown does too much
7 # and requires indentation to output preformatted text.
10 use PublicInbox::Linkify;
11 use PublicInbox::Hval qw(ascii_html);
22 lei-forget-external(1)
23 lei-forget-mail-sync(1)
49 public-inbox-config(5)
50 public-inbox-config(5)
51 public-inbox-convert(1)
52 public-inbox-daemon(8)
55 public-inbox-glossary(7)
63 public-inbox-overview(7)
65 public-inbox-v1-format(5)
66 public-inbox-v2-format(5)
70 my ($n) = (/([\w\-\.]+)/);
71 $xurls{$_} = "$n.html";
72 $xurls{$n} = "$n.html";
75 for (qw[copydatabase(1) xapian-compact(1)]) {
76 my ($n) = (/([\w\-\.]+)/);
77 $xurls{$_} = ".$n.1.html"
80 for (qw[make(1) flock(2) setrlimit(2) vfork(2) tmpfs(5)]) {
81 my ($n, $s) = (/([\w\-]+)\((\d)\)/);
82 $xurls{$_} = "http://www.man7.org/linux/man-pages/man$s/$n.$s.html";
101 gitrepository-layout(5)
103 my ($n) = (/([\w\-\.]+)/);
104 $xurls{$_} = "https://kernel.org/pub/software/scm/git/docs/$n.html"
113 my ($n) = (/([\w\-\.]+)/);
114 $xurls{$_} = "https://www.freedesktop.org/software/systemd/man/$n.html";
117 $xurls{'netrc(5)'} = 'https://manpages.debian.org/stable/ftp/netrc.5.en.html';
118 $xurls{'mbsync(1)'} =
119 'https://manpages.debian.org/stable/isync/mbsync.1.en.html';
120 $xurls{'offlineimap(1)'} =
121 'https://manpages.debian.org/stable/offlineimap/offlineimap.1.en.html';
123 'https://spamassassin.apache.org/full/3.4.x/doc/spamc.html';
124 $xurls{'grok-pull'} =
125 'https://git.kernel.org/pub/scm/utils/grokmirror/grokmirror.git' .
126 '/tree/man/grok-pull.1.rst';
127 $xurls{'git-filter-repo(1)'} = 'https://github.com/newren/git-filter-repo'.
128 '/blob/master/Documentation/git-filter-repo.txt';
129 $xurls{'ssoma(1)'} = 'https://ssoma.public-inbox.org/ssoma.txt';
130 $xurls{'cgitrc(5)'} = 'https://git.zx2c4.com/cgit/tree/cgitrc.5.txt';
131 $xurls{'prove(1)'} = 'https://perldoc.perl.org/prove.html';
132 $xurls{'mbox(5)'} = 'https://manpages.debian.org/stable/mutt/mbox.5.en.html';
133 $xurls{'mmdf(5)'} = 'https://manpages.debian.org/stable/mutt/mmdf.5.en.html';
135 my $str = do { local $/; <STDIN> };
136 my ($title) = ($str =~ /\A([^\n]+)/);
137 if ($str =~ /^NAME\n\s+([^\n]+)/sm) {
138 # don't link to ourselves
140 if ($title =~ /([\w\.\-]+)/) {
144 $title = ascii_html($title);
145 my $l = PublicInbox::Linkify->new;
146 $str = $l->linkify_1($str);
147 $str = ascii_html($str);
149 # longest matches, first
150 my @keys = sort { length($b) <=> length($a) } keys %xurls;
151 my $xkeys = join('|', map { quotemeta } @keys);
152 $str =~ s,(?<![>\w_])($xkeys)(?!(?:[\w<\-]|\.html)),
153 qq(<a\nhref=").$xurls{$1}.qq(">$1).($2//'').'</a>',sge;
155 $str = $l->linkify_2($str);
157 print '<html><head>',
158 qq(<meta\nhttp-equiv="Content-Type"\ncontent="text/html; charset=utf-8"\n/>),
159 "<title>$title</title>",
160 "</head><body><pre>", $str , '</pre></body></html>';
163 # keep mtime on website consistent so clients can cache
164 if (-f STDIN && -f STDOUT) {
165 my @st = stat(STDIN);
166 utime($st[8], $st[9], \*STDOUT);