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