2 # n.b. this is invoked via $(PERL) in makefiles
3 # Copyright (C) all contributors <meta@public-inbox.org>
4 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 # Stupid script to make HTML from preformatted, utf-8 text versions,
7 # only generating links for http(s). Markdown does too much
8 # and requires indentation to output preformatted text.
10 use PublicInbox::Linkify;
11 use PublicInbox::Hval qw(ascii_html);
24 lei-forget-external(1)
25 lei-forget-mail-sync(1)
39 lei-mail-sync-overview(7)
44 lei-refresh-mail-sync(1)
54 public-inbox-config(5)
55 public-inbox-config(5)
56 public-inbox-convert(1)
57 public-inbox-daemon(8)
60 public-inbox-glossary(7)
69 public-inbox-overview(7)
72 public-inbox-v1-format(5)
73 public-inbox-v2-format(5)
77 my ($n) = (/([\w\-\.]+)/);
78 $xurls{$_} = "$n.html";
79 $xurls{$n} = "$n.html";
80 /\Alei-(.+?)\(1\)\z/ and $xurls{"lei $1"} = "$n.html";
83 $xurls{'lei/store'} = 'lei-store-format.html';
85 for (qw[make(1) flock(2) setrlimit(2) vfork(2) tmpfs(5) inotify(7) unix(7)
87 my ($n, $s) = (/([\w\-]+)\((\d)\)/);
88 $xurls{$_} = "https://www.man7.org/linux/man-pages/man$s/$n.$s.html";
107 gitrepository-layout(5)
110 my ($n) = (/([\w\-\.]+)/);
111 $xurls{$_} = "https://kernel.org/pub/software/scm/git/docs/$n.html"
120 my ($n) = (/([\w\-\.]+)/);
121 $xurls{$_} = "https://www.freedesktop.org/software/systemd/man/$n.html";
124 # favor upstream docs if they exist, use manpages.debian.org if they don't
125 $xurls{'netrc(5)'} = 'https://manpages.debian.org/stable/ftp/netrc.5.en.html';
126 $xurls{'mbsync(1)'} =
127 'https://manpages.debian.org/stable/isync/mbsync.1.en.html';
128 $xurls{'offlineimap(1)'} =
129 'https://manpages.debian.org/stable/offlineimap/offlineimap.1.en.html';
131 'https://spamassassin.apache.org/full/3.4.x/doc/spamc.html';
132 $xurls{'grok-pull'} =
133 'https://git.kernel.org/pub/scm/utils/grokmirror/grokmirror.git' .
134 '/tree/man/grok-pull.1.rst';
135 $xurls{'git-filter-repo(1)'} = 'https://github.com/newren/git-filter-repo'.
136 '/blob/master/Documentation/git-filter-repo.txt';
137 $xurls{'ssoma(1)'} = 'https://ssoma.public-inbox.org/ssoma.txt';
138 $xurls{'cgitrc(5)'} = 'https://git.zx2c4.com/cgit/tree/cgitrc.5.txt';
139 $xurls{'prove(1)'} = 'https://perldoc.perl.org/prove.html';
140 $xurls{'mbox(5)'} = 'https://manpages.debian.org/stable/mutt/mbox.5.en.html';
141 $xurls{'mmdf(5)'} = 'https://manpages.debian.org/stable/mutt/mmdf.5.en.html';
142 $xurls{'mutt(1)'} = 'https://manpages.debian.org/stable/mutt/mutt.1.en.html';
143 $xurls{'torsocks(1)'} =
144 'https://manpages.debian.org/stable/torsocks/torsocks.1.en.html';
145 $xurls{'curl(1)'} = 'https://manpages.debian.org/stable/curl/curl.1.en.html';
146 $xurls{'copydatabase(1)'} =
147 'https://manpages.debian.org/stable/xapian-tools/copydatabase.1.en.html';
148 $xurls{'xapian-compact(1)'} =
149 'https://manpages.debian.org/stable/xapian-tools/xapian-compact.1.en.html';
150 $xurls{'gzip(1)'} = 'https://manpages.debian.org/stable/gzip/gzip.1.en.html';
152 'https://manpages.debian.org/stable/coreutils/chmod.1.en.html';
153 $xurls{'kqueue(2)'} =
154 'https://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2';
155 $xurls{'notmuch(1)'} = 'https://notmuchmail.org/manpages/notmuch-1/';
156 $xurls{'mairix(1)'} =
157 'https://manpages.debian.org/stable/mairix/mairix.1.en.html';
159 my $str = do { local $/; <STDIN> };
160 my ($title) = ($str =~ /\A([^\n]+)/);
161 if ($str =~ /^NAME\n\s+([^\n]+)/sm) {
162 # don't link to ourselves
164 if ($title =~ /([\w\.\-]+)/) {
167 if ($title =~ /\blei-([\w\-]+)\b/) {
168 delete $xurls{"lei $1"};
171 $title = ascii_html($title);
172 my $l = PublicInbox::Linkify->new;
173 $str = $l->linkify_1($str);
174 $str = ascii_html($str);
176 # longest matches, first
177 my @keys = sort { length($b) <=> length($a) } keys %xurls;
178 my $xkeys = join('|', map { quotemeta } @keys);
179 $str =~ s,(?<![>\w_])($xkeys)(?!(?:[\w<\-]|\.html)),
180 qq(<a\nhref=").$xurls{$1}.qq(">$1).($2//'').'</a>',sge;
182 $str = $l->linkify_2($str);
184 print '<html><head>',
185 qq(<meta\nhttp-equiv="Content-Type"\ncontent="text/html; charset=utf-8"\n/>),
186 "<title>$title</title>",
187 "</head><body><pre>", $str , '</pre></body></html>';