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);
18 lei-forget-external(1)
25 public-inbox-compact(1)
26 public-inbox-config(5)
27 public-inbox-convert(1)
28 public-inbox-daemon(8)
37 public-inbox-overview(7)
39 public-inbox-v1-format(5)
40 public-inbox-v2-format(5)
44 my ($n) = (/([\w\-\.]+)/);
45 $xurls{$_} = "$n.html";
46 $xurls{$n} = "$n.html";
49 for (qw[copydatabase(1) xapian-compact(1)]) {
50 my ($n) = (/([\w\-\.]+)/);
51 $xurls{$_} = ".$n.1.html"
54 for (qw[make(1) flock(2) setrlimit(2) vfork(2) tmpfs(5)]) {
55 my ($n, $s) = (/([\w\-]+)\((\d)\)/);
56 $xurls{$_} = "http://www.man7.org/linux/man-pages/man$s/$n.$s.html";
74 gitrepository-layout(5)
76 my ($n) = (/([\w\-\.]+)/);
77 $xurls{$_} = "https://kernel.org/pub/software/scm/git/docs/$n.html"
86 my ($n) = (/([\w\-\.]+)/);
87 $xurls{$_} = "https://www.freedesktop.org/software/systemd/man/$n.html";
90 $xurls{'netrc(5)'} = 'https://manpages.debian.org/stable/ftp/netrc.5.en.html';
92 'https://manpages.debian.org/stable/isync/mbsync.1.en.html';
93 $xurls{'offlineimap(1)'} =
94 'https://manpages.debian.org/stable/offlineimap/offlineimap.1.en.html';
96 'https://spamassassin.apache.org/full/3.4.x/doc/spamc.html';
98 'https://git.kernel.org/pub/scm/utils/grokmirror/grokmirror.git' .
99 '/tree/man/grok-pull.1.rst';
100 $xurls{'git-filter-repo(1)'} = 'https://github.com/newren/git-filter-repo'.
101 '/blob/master/Documentation/git-filter-repo.txt';
102 $xurls{'ssoma(1)'} = 'https://ssoma.public-inbox.org/ssoma.txt';
103 $xurls{'cgitrc(5)'} = 'https://git.zx2c4.com/cgit/tree/cgitrc.5.txt';
104 $xurls{'prove(1)'} = 'https://perldoc.perl.org/prove.html';
106 my $str = do { local $/; <STDIN> };
107 my ($title) = ($str =~ /\A([^\n]+)/);
108 if ($str =~ /^NAME\n\s+([^\n]+)/sm) {
109 # don't link to ourselves
111 if ($title =~ /([\w\.\-]+)/) {
115 $title = ascii_html($title);
116 my $l = PublicInbox::Linkify->new;
117 $str = $l->linkify_1($str);
118 $str = ascii_html($str);
120 # longest matches, first
121 my @keys = sort { length($b) <=> length($a) } keys %xurls;
122 my $xkeys = join('|', map { quotemeta } @keys);
123 $str =~ s,(?<![>\w_])($xkeys)(?!(?:[\w<\-]|\.html)),
124 qq(<a\nhref=").$xurls{$1}.qq(">$1).($2//'').'</a>',sge;
126 $str = $l->linkify_2($str);
128 print '<html><head>',
129 qq(<meta\nhttp-equiv="Content-Type"\ncontent="text/html; charset=utf-8"\n/>),
130 "<title>$title</title>",
131 "</head><body><pre>", $str , '</pre></body></html>';
134 # keep mtime on website consistent so clients can cache
135 if (-f STDIN && -f STDOUT) {
136 my @st = stat(STDIN);
137 utime($st[8], $st[9], \*STDOUT);