]> Sergey Matveev's repositories - public-inbox.git/blob - Documentation/txt2pre
doc: txt2pre: add references to newish manpages
[public-inbox.git] / Documentation / txt2pre
1 #!/usr/bin/env perl
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>
4 #
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.
8 use strict;
9 use warnings;
10 use PublicInbox::Linkify;
11 use PublicInbox::Hval qw(ascii_html);
12 my %xurls;
13 for (qw[lei(1)
14         lei-add-external(1)
15         lei-add-watch(1)
16         lei-blob(1)
17         lei-config(1)
18         lei-convert(1)
19         lei-daemon(8)
20         lei-daemon-kill(1)
21         lei-daemon-pid(1)
22         lei-edit-search(1)
23         lei-export-kw(1)
24         lei-forget-external(1)
25         lei-forget-mail-sync(1)
26         lei-forget-search(1)
27         lei-import(1)
28         lei-index(1)
29         lei-init(1)
30         lei-inspect(1)
31         lei-lcat(1)
32         lei-ls-external(1)
33         lei-ls-label(1)
34         lei-ls-mail-source(1)
35         lei-ls-mail-sync(1)
36         lei-ls-search(1)
37         lei-ls-watch(1)
38         lei-mail-diff(1)
39         lei-mail-sync-overview(7)
40         lei-overview(7)
41         lei-p2q(1)
42         lei-q(1)
43         lei-rediff(1)
44         lei-refresh-mail-sync(1)
45         lei-rm(1)
46         lei-rm-watch(1)
47         lei-security(7)
48         lei-store-format(5)
49         lei-tag(1)
50         lei-up(1)
51         public-inbox.cgi(1)
52         public-inbox-clone(1)
53         public-inbox-config(5)
54         public-inbox-config(5)
55         public-inbox-convert(1)
56         public-inbox-daemon(8)
57         public-inbox-edit(1)
58         public-inbox-fetch(1)
59         public-inbox-glossary(7)
60         public-inbox-httpd(1)
61         public-inbox-imapd(1)
62         public-inbox-index(1)
63         public-inbox-init(1)
64         public-inbox-learn(1)
65         public-inbox-mda(1)
66         public-inbox-nntpd(1)
67         public-inbox-overview(7)
68         public-inbox-purge(1)
69         public-inbox-v1-format(5)
70         public-inbox-v2-format(5)
71         public-inbox-watch(1)
72         public-inbox-xcpdb(1)
73 ]) {
74         my ($n) = (/([\w\-\.]+)/);
75         $xurls{$_} = "$n.html";
76         $xurls{$n} = "$n.html";
77 }
78
79 for (qw[copydatabase(1) xapian-compact(1)]) {
80         my ($n) = (/([\w\-\.]+)/);
81         $xurls{$_} = ".$n.1.html"
82 }
83
84 for (qw[make(1) flock(2) setrlimit(2) vfork(2) tmpfs(5)]) {
85         my ($n, $s) = (/([\w\-]+)\((\d)\)/);
86         $xurls{$_} = "http://www.man7.org/linux/man-pages/man$s/$n.$s.html";
87 }
88
89 for (qw[git(1)
90         git-am(1)
91         git-apply(1)
92         git-config(1)
93         git-credential(1)
94         git-daemon(1)
95         git-diff(1)
96         git-fast-import(1)
97         git-fetch(1)
98         git-filter-branch(1)
99         git-format-patch(1)
100         git-gc(1)
101         git-http-backend(1)
102         git-imap-send(1)
103         git-init(1)
104         git-send-email(1)
105         gitrepository-layout(5)
106 ]) {
107         my ($n) = (/([\w\-\.]+)/);
108         $xurls{$_} = "https://kernel.org/pub/software/scm/git/docs/$n.html"
109 }
110
111 for (qw[
112         sd_listen_fds(3)
113         systemd(1)
114         systemd.unit(5)
115         systemd.socket(5)
116 ]) {
117         my ($n) = (/([\w\-\.]+)/);
118         $xurls{$_} = "https://www.freedesktop.org/software/systemd/man/$n.html";
119 }
120
121 $xurls{'netrc(5)'} = 'https://manpages.debian.org/stable/ftp/netrc.5.en.html';
122 $xurls{'mbsync(1)'} =
123         'https://manpages.debian.org/stable/isync/mbsync.1.en.html';
124 $xurls{'offlineimap(1)'} =
125         'https://manpages.debian.org/stable/offlineimap/offlineimap.1.en.html';
126 $xurls{'spamc(1)'} =
127         'https://spamassassin.apache.org/full/3.4.x/doc/spamc.html';
128 $xurls{'grok-pull'} =
129         'https://git.kernel.org/pub/scm/utils/grokmirror/grokmirror.git' .
130         '/tree/man/grok-pull.1.rst';
131 $xurls{'git-filter-repo(1)'} = 'https://github.com/newren/git-filter-repo'.
132                         '/blob/master/Documentation/git-filter-repo.txt';
133 $xurls{'ssoma(1)'} = 'https://ssoma.public-inbox.org/ssoma.txt';
134 $xurls{'cgitrc(5)'} = 'https://git.zx2c4.com/cgit/tree/cgitrc.5.txt';
135 $xurls{'prove(1)'} = 'https://perldoc.perl.org/prove.html';
136 $xurls{'mbox(5)'} = 'https://manpages.debian.org/stable/mutt/mbox.5.en.html';
137 $xurls{'mmdf(5)'} = 'https://manpages.debian.org/stable/mutt/mmdf.5.en.html';
138
139 my $str = do { local $/; <STDIN> };
140 my ($title) = ($str =~ /\A([^\n]+)/);
141 if ($str =~ /^NAME\n\s+([^\n]+)/sm) {
142         # don't link to ourselves
143         $title = $1;
144         if ($title =~ /([\w\.\-]+)/) {
145                 delete $xurls{$1};
146         }
147 }
148 $title = ascii_html($title);
149 my $l = PublicInbox::Linkify->new;
150 $str = $l->linkify_1($str);
151 $str = ascii_html($str);
152
153 # longest matches, first
154 my @keys = sort { length($b) <=> length($a) } keys %xurls;
155 my $xkeys = join('|', map { quotemeta } @keys);
156 $str =~ s,(?<![>\w_])($xkeys)(?!(?:[\w<\-]|\.html)),
157         qq(<a\nhref=").$xurls{$1}.qq(">$1).($2//'').'</a>',sge;
158
159 $str = $l->linkify_2($str);
160
161 print '<html><head>',
162   qq(<meta\nhttp-equiv="Content-Type"\ncontent="text/html; charset=utf-8"\n/>),
163   "<title>$title</title>",
164   "</head><body><pre>",  $str , '</pre></body></html>';
165 STDOUT->flush;
166
167 # keep mtime on website consistent so clients can cache
168 if (-f STDIN && -f STDOUT) {
169         my @st = stat(STDIN);
170         utime($st[8], $st[9], \*STDOUT);
171 }