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