2 # Copyright (C) 2014-2020 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);
13 for (qw[public-inbox.cgi(1)
14 public-inbox-compact(1)
15 public-inbox-config(5)
16 public-inbox-convert(1)
17 public-inbox-daemon(8)
25 public-inbox-overview(7)
27 public-inbox-v1-format(5)
28 public-inbox-v2-format(5)
32 my ($n) = (/([\w\-\.]+)/);
33 $xurls{$_} = "$n.html";
34 $xurls{$n} = "$n.html";
37 for (qw[copydatabase(1) xapian-compact(1)]) {
38 my ($n) = (/([\w\-\.]+)/);
39 $xurls{$_} = ".$n.1.html"
42 for (qw[flock(2) setrlimit(2) vfork(2)]) {
43 my ($n, $s) = (/([\w\-]+)\((\d)\)/);
44 $xurls{$_} = "http://www.man7.org/linux/man-pages/man2/$n.$s.html";
59 gitrepository-layout(5)
61 my ($n) = (/([\w\-\.]+)/);
62 $xurls{$_} = "https://kernel.org/pub/software/scm/git/docs/$n.html"
71 my ($n) = (/([\w\-\.]+)/);
72 $xurls{$_} = "https://www.freedesktop.org/software/systemd/man/$n.html";
76 'https://spamassassin.apache.org/full/3.4.x/doc/spamc.html';
78 'https://git.kernel.org/pub/scm/utils/grokmirror/grokmirror.git' .
79 '/tree/man/grok-pull.1.rst';
80 $xurls{'git-filter-repo(1)'} = 'https://github.com/newren/git-filter-repo'.
81 './blob/master/Documentation/git-filter-repo.txt';
82 $xurls{'ssoma(1)'} = 'https://ssoma.public-inbox.org/ssoma.txt';
83 $xurls{'cgitrc(5)'} = 'https://git.zx2c4.com/cgit/tree/cgitrc.5.txt';
85 my $str = do { local $/; <STDIN> };
86 my ($title) = ($str =~ /\A([^\n]+)/);
87 if ($str =~ /^NAME\n\s+([^\n]+)/sm) {
88 # don't link to ourselves
90 if ($title =~ /([\w\.\-]+)/) {
94 $title = ascii_html($title);
95 my $l = PublicInbox::Linkify->new;
96 $str = $l->linkify_1($str);
97 $str = ascii_html($str);
99 # longest matches, first
100 my @keys = sort { length($b) <=> length($a) } keys %xurls;
101 my $xkeys = join('|', map { quotemeta } @keys);
102 $str =~ s,(?<![>\w_])($xkeys)(?!(?:[\w<\-]|\.html)),
103 qq(<a\nhref=").$xurls{$1}.qq(">$1).($2//'').'</a>',sge;
105 $str = $l->linkify_2($str);
107 print '<html><head>',
108 qq(<meta\nhttp-equiv="Content-Type"\ncontent="text/html; charset=utf-8"\n/>),
109 "<title>$title</title>",
110 "</head><body><pre>", $str , '</pre></body></html>';
113 # keep mtime on website consistent so clients can cache
114 if (-f STDIN && -f STDOUT) {
115 my @st = stat(STDIN);
116 utime($st[8], $st[9], \*STDOUT);