]> Sergey Matveev's repositories - public-inbox.git/blob - Documentation/txt2pre
doc: add more 3rd-party refs, use Debian manpages for xapian
[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[make(1) flock(2) setrlimit(2) vfork(2) tmpfs(5)]) {
80         my ($n, $s) = (/([\w\-]+)\((\d)\)/);
81         $xurls{$_} = "http://www.man7.org/linux/man-pages/man$s/$n.$s.html";
82 }
83
84 for (qw[git(1)
85         git-am(1)
86         git-apply(1)
87         git-config(1)
88         git-credential(1)
89         git-daemon(1)
90         git-diff(1)
91         git-fast-import(1)
92         git-fetch(1)
93         git-filter-branch(1)
94         git-format-patch(1)
95         git-gc(1)
96         git-http-backend(1)
97         git-imap-send(1)
98         git-init(1)
99         git-send-email(1)
100         gitrepository-layout(5)
101         gitglossary(7)
102 ]) {
103         my ($n) = (/([\w\-\.]+)/);
104         $xurls{$_} = "https://kernel.org/pub/software/scm/git/docs/$n.html"
105 }
106
107 for (qw[
108         sd_listen_fds(3)
109         systemd(1)
110         systemd.unit(5)
111         systemd.socket(5)
112 ]) {
113         my ($n) = (/([\w\-\.]+)/);
114         $xurls{$_} = "https://www.freedesktop.org/software/systemd/man/$n.html";
115 }
116
117 # favor upstream docs if they exist, use manpages.debian.org if they don't
118 $xurls{'netrc(5)'} = 'https://manpages.debian.org/stable/ftp/netrc.5.en.html';
119 $xurls{'mbsync(1)'} =
120         'https://manpages.debian.org/stable/isync/mbsync.1.en.html';
121 $xurls{'offlineimap(1)'} =
122         'https://manpages.debian.org/stable/offlineimap/offlineimap.1.en.html';
123 $xurls{'spamc(1)'} =
124         'https://spamassassin.apache.org/full/3.4.x/doc/spamc.html';
125 $xurls{'grok-pull'} =
126         'https://git.kernel.org/pub/scm/utils/grokmirror/grokmirror.git' .
127         '/tree/man/grok-pull.1.rst';
128 $xurls{'git-filter-repo(1)'} = 'https://github.com/newren/git-filter-repo'.
129                         '/blob/master/Documentation/git-filter-repo.txt';
130 $xurls{'ssoma(1)'} = 'https://ssoma.public-inbox.org/ssoma.txt';
131 $xurls{'cgitrc(5)'} = 'https://git.zx2c4.com/cgit/tree/cgitrc.5.txt';
132 $xurls{'prove(1)'} = 'https://perldoc.perl.org/prove.html';
133 $xurls{'mbox(5)'} = 'https://manpages.debian.org/stable/mutt/mbox.5.en.html';
134 $xurls{'mmdf(5)'} = 'https://manpages.debian.org/stable/mutt/mmdf.5.en.html';
135 $xurls{'torsocks(1)'} =
136         'https://manpages.debian.org/stable/torsocks/torsocks.1.en.html';
137 $xurls{'curl(1)'} = 'https://manpages.debian.org/stable/curl/curl.1.en.html';
138 $xurls{'copydatabase(1)'} =
139  'https://manpages.debian.org/stable/xapian-tools/copydatabase.1.en.html';
140 $xurls{'xapian-compact(1)'} =
141  'https://manpages.debian.org/stable/xapian-tools/xapian-compact.1.en.html';
142
143 my $str = do { local $/; <STDIN> };
144 my ($title) = ($str =~ /\A([^\n]+)/);
145 if ($str =~ /^NAME\n\s+([^\n]+)/sm) {
146         # don't link to ourselves
147         $title = $1;
148         if ($title =~ /([\w\.\-]+)/) {
149                 delete $xurls{$1};
150         }
151 }
152 $title = ascii_html($title);
153 my $l = PublicInbox::Linkify->new;
154 $str = $l->linkify_1($str);
155 $str = ascii_html($str);
156
157 # longest matches, first
158 my @keys = sort { length($b) <=> length($a) } keys %xurls;
159 my $xkeys = join('|', map { quotemeta } @keys);
160 $str =~ s,(?<![>\w_])($xkeys)(?!(?:[\w<\-]|\.html)),
161         qq(<a\nhref=").$xurls{$1}.qq(">$1).($2//'').'</a>',sge;
162
163 $str = $l->linkify_2($str);
164
165 print '<html><head>',
166   qq(<meta\nhttp-equiv="Content-Type"\ncontent="text/html; charset=utf-8"\n/>),
167   "<title>$title</title>",
168   "</head><body><pre>",  $str , '</pre></body></html>';
169 STDOUT->flush;
170
171 # keep mtime on website consistent so clients can cache
172 if (-f STDIN && -f STDOUT) {
173         my @st = stat(STDIN);
174         utime($st[8], $st[9], \*STDOUT);
175 }