Skip to content

Commit f1b49a1

Browse files
committed
Convert SSI includes to tt includes in manpages
This was a bigger effort, and involves a new target, manhtml. Reviewed-by: Anton Arapov <[email protected]> Reviewed-by: Tomas Vavra <[email protected]> (Merged from openssl#430)
1 parent efcfb4a commit f1b49a1

12 files changed

+145
-215
lines changed

Makefile

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ TECHNICAL_POLICIES=$(filter-out $(CHECKOUTS)/technical-policies/policies/README.
128128
@rm -f $@
129129
./bin/from-tt $<
130130

131-
all: suball subdocs manmaster mancross sitemap akamai-purge
131+
all: suball subdocs manmastertts mancross manhtml sitemap akamai-purge
132132

133133
suball: $(SIMPLE) $(SRCLISTS)
134134

135135
relupd: suball docs sitemap akamai-purge
136136

137-
docs: subdocs manpages mancross
137+
docs: subdocs manpagetts mancross manhtml
138138

139139
subdocs: $(SIMPLEDOCS)
140140

@@ -171,9 +171,9 @@ bin/md-to-html5: inc/pandoc-template.html5
171171
##
172172
## A lot of the work is made with generated rules.
173173

174-
# makemanpages1 and makemanpages3 creates rules for targets like man-pages-1.1.1,
175-
# to build the set of man-pages. makemanpages1 is used for pre-3.0 OpenSSL,
176-
# while makemanpages3 is used for OpenSSL 3.0 and on.
174+
# makemanpagetts1 and makemanpagetts3 creates rules for targets like man-pagetts-1.1.1,
175+
# to build the set of man-page templates. makemanpagetts1 is used for pre-3.0 OpenSSL,
176+
# while makemanpagetts3 is used for OpenSSL 3.0 and on.
177177
# makemanapropos creates rules for targets like man-apropos-1.1.1, to build
178178
# 'apropos' like indexes for all the manpages.
179179
# makemanindexes creates rules for targets like man-index-1.1.1, to build the
@@ -182,26 +182,26 @@ bin/md-to-html5: inc/pandoc-template.html5
182182
# $(1) = input directory in CHECKOUTS, $(2) = release version
183183

184184
# This variant is for pre-3.0 documentation
185-
define makemanpages1
186-
man-pages-$(2):
185+
define makemanpagetts1
186+
man-pagetts-$(2):
187187
@rm -rf docs/man$(2)
188188
@mkdir -p docs/man$(2) \
189189
docs/man$(2)/man1 \
190190
docs/man$(2)/man3 \
191191
docs/man$(2)/man5 \
192192
docs/man$(2)/man7
193-
./bin/mk-manpages $(CHECKOUTS)/$(1)/doc $(2) docs/man$(2)
193+
./bin/mk-manpagetts $(CHECKOUTS)/$(1)/doc $(2) docs/man$(2)
194194
endef
195195
# This variant is for 3.0 documentation
196-
define makemanpages3
197-
man-pages-$(2):
196+
define makemanpagetts3
197+
man-pagetts-$(2):
198198
@rm -rf docs/man$(2)
199199
@mkdir -p docs/man$(2) \
200200
docs/man$(2)/man1 \
201201
docs/man$(2)/man3 \
202202
docs/man$(2)/man5 \
203203
docs/man$(2)/man7
204-
./bin/mk-manpages3 $(CHECKOUTS)/$(1) $(2) docs/man$(2)
204+
./bin/mk-manpagetts3 $(CHECKOUTS)/$(1) $(2) docs/man$(2)
205205
endef
206206
define makemanapropos
207207
docs/man$(2)/man1/index.inc: bin/mk-apropos Makefile
@@ -246,33 +246,33 @@ endef
246246
define makemandirdata
247247
docs/man$(2)/man1/dirdata.yaml: docs/sub-dirdata.yaml.tt bin/from-tt Makefile
248248
./bin/from-tt -d docs/man$(2)/man1 \
249-
releases='$(MANSERIES)' release='$(2)' \
249+
releases='$(MANSERIES)' release='$(2)' sectnum=1 \
250250
< $$< > $$@
251251
docs/man$(2)/man3/dirdata.yaml: docs/sub-dirdata.yaml.tt bin/from-tt Makefile
252252
./bin/from-tt -d docs/man$(2)/man3 \
253-
releases='$(MANSERIES)' release='$(2)' \
253+
releases='$(MANSERIES)' release='$(2)' sectnum=3 \
254254
< $$< > $$@
255255
docs/man$(2)/man5/dirdata.yaml: docs/sub-dirdata.yaml.tt bin/from-tt Makefile
256256
./bin/from-tt -d docs/man$(2)/man5 \
257-
releases='$(MANSERIES)' release='$(2)' \
257+
releases='$(MANSERIES)' release='$(2)' sectnum=5 \
258258
< $$< > $$@
259259
docs/man$(2)/man7/dirdata.yaml: docs/sub-dirdata.yaml.tt bin/from-tt Makefile
260260
./bin/from-tt -d docs/man$(2)/man7 \
261-
releases='$(MANSERIES)' release='$(2)' \
261+
releases='$(MANSERIES)' release='$(2)' sectnum=7 \
262262
< $$< > $$@
263263
docs/man$(2)/dirdata.yaml: docs/sub-dirdata.yaml.tt bin/from-tt Makefile
264264
./bin/from-tt -d docs/man$(2) \
265265
releases='$(MANSERIES)' release='$(2)' \
266266
< $$< > $$@
267267
endef
268268
define makemanuals1
269-
$(eval $(call makemanpages1,$(1),$(2)))
269+
$(eval $(call makemanpagetts1,$(1),$(2)))
270270
$(eval $(call makemanapropos,$(1),$(2)))
271271
$(eval $(call makemanindexes,$(1),$(2)))
272272
$(eval $(call makemandirdata,$(1),$(2)))
273273
endef
274274
define makemanuals3
275-
$(eval $(call makemanpages3,$(1),$(2)))
275+
$(eval $(call makemanpagetts3,$(1),$(2)))
276276
$(eval $(call makemanapropos,$(1),$(2)))
277277
$(eval $(call makemanindexes,$(1),$(2)))
278278
$(eval $(call makemandirdata,$(1),$(2)))
@@ -292,19 +292,40 @@ $(foreach S,$(MANSERIES3),$(eval $(call makemanuals3,openssl-$(S),$(S))))
292292
# source from $(CHECKOUTS)/openssl-x.y.z-stable/doc
293293
$(foreach S,$(MANSERIES1),$(eval $(call makemanuals1,openssl-$(S)-stable,$(S))))
294294

295-
MANMASTER_TARGETS = \
296-
man-pages-master docs/manmaster/index.html \
297-
$(foreach SEC,1 3 5 7, docs/manmaster/man$(SEC)/index.html)
298-
manmaster: $(MANMASTER_TARGETS)
299-
MANPAGES_TARGETS = \
295+
MANMASTER_DIRS = \
296+
$(foreach SEC,1 3 5 7, docs/manmaster/man$(SEC))
297+
MANMASTERTT_TARGETS = \
298+
man-pagetts-master \
299+
docs/manmaster/dirdata.yaml docs/manmaster/index.html \
300+
$(foreach D,$(MANMASTER_DIRS), $(D)/dirdata.yaml $(D)/index.html)
301+
manmastertts: $(MANMASTERTT_TARGETS)
302+
MANPAGE_DIRS = \
300303
$(foreach S,$(MANSERIES), \
301-
man-pages-$(S) docs/man$(S)/index.html \
302-
$(foreach SEC,1 3 5 7, docs/man$(S)/man$(SEC)/index.html))
303-
manpages: manmaster $(MANPAGES_TARGETS)
304+
$(foreach SEC,1 3 5 7, docs/man$(S)/man$(SEC)))
305+
MANPAGETT_TARGETS = \
306+
$(foreach S,$(MANSERIES), man-pagetts-$(S) \
307+
docs/man$(S)/dirdata.yaml docs/man$(S)/index.html) \
308+
$(foreach D,$(MANPAGE_DIRS), $(D)/dirdata.yaml $(D)/index.html)
309+
manpagetts: manmastertts $(MANPAGETT_TARGETS)
304310

305311
mancross:
306312
./bin/mk-mancross master $(MANSERIES)
307313

314+
# We can't get all the files when make is started, but we can make the
315+
# patterns for a for loop.
316+
MANHTML_TTPATTERNS=$(foreach D,$(MANMASTER_DIRS) $(MANPAGE_DIRS), $(D)/*.md.tt)
317+
manhtml:
318+
@set -e; for t in $(MANHTML_TTPATTERNS); do \
319+
if ! [ -f "$$t" ]; then continue; fi; \
320+
d="$$(dirname $$t)"; \
321+
h="$$(basename "$$t" .md.tt)"; \
322+
i=; \
323+
if [ "$$h" = "index" ]; then i=" -i"; fi; \
324+
echo "$$t -> $$h.html"; \
325+
./bin/from-tt -d "$$d" < "$$d/$$h.md.tt" \
326+
| ./bin/md-to-html5$$i -o "$$d/$$h.html"; \
327+
done
328+
308329
docs/manpages.md: docs/manpages.md.tt Makefile bin/from-tt
309330
@rm -f $@
310331
./bin/from-tt releases='master $(MANSERIES)' $<

bin/mk-apropos

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
dir=$1
55
cd $dir
66

7-
for m in `find . -name '*.html' | sort`; do
8-
description=`grep -F '<!-- OSSL: description:' $m | sed -e 's|^[^:]*: *||' -e 's|^[^:]*: *||' -e 's| *-->||'`
7+
for m in `find . -name '*.md.tt' | sort`; do
8+
description=`grep '^OSSL-description:' $m | sed -e 's|^[^:]*: *||' -e 's|^ *"||' -e 's|" *||'`
99
# If there isn't a description, it isn't a manpage and should not be
1010
# included
1111
if [ "$description" = "" ]; then
1212
continue
1313
fi
1414
manfile=`echo $m | sed -e 's|\./||'`
15-
manname=`basename $manfile .html`
15+
manname=`basename $manfile .md.tt`
1616
origmanfile=`echo $manfile | sed -e "s|^$subdir|$origsubdir|"`
17-
echo "<tr><td><a href=\"$manfile\">$manname</a></td><td>$description</td></tr>"
17+
echo "| [$manname]($manname.html) | $description |"
1818
done

bin/mk-mancross

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,31 @@ for r in $releases; do
2121
echo >&2 -n "$r : "
2222
for s in 1 3 5 7; do
2323
echo >&2 -n $s
24-
for f in docs/man$r/man$s/*.html; do
24+
for f in docs/man$r/man$s/*.md.tt; do
2525
$debug -n '.'
26-
# Check that it's a rendered manpage
27-
if grep -F '<!-- OSSL: description:' $f > /dev/null; then
28-
existsin=''
29-
b=`basename $f .html`
30-
for x in $releases; do
31-
if [ "$x" = "$r" ]; then
32-
continue
33-
fi
34-
if [ -f "docs/man$x/man$s/$b.html" ]; then
35-
existsin="$existsin $x"
36-
fi
37-
done
38-
(
39-
if [ "$existsin" != "" ]; then
40-
cat <<EOF
41-
<section>
42-
<h1>This manpage</h1>
43-
<ul>
44-
EOF
45-
for x in $existsin; do
46-
cat <<EOF
47-
<li><a href="/docs/man$x/man$s/$b.html">$x version</a></li>
26+
existsin=''
27+
b=`basename $f .md.tt`
28+
for x in $releases; do
29+
if [ "$x" = "$r" ]; then
30+
continue
31+
fi
32+
if [ -f "docs/man$x/man$s/$b.md.tt" ]; then
33+
existsin="$existsin $x"
34+
fi
35+
done
36+
(
37+
if [ "$existsin" != "" ]; then
38+
cat <<EOF
39+
sidebar: |
40+
# This manpage
4841
EOF
49-
done
42+
for x in $existsin; do
5043
cat <<EOF
51-
</ul>
52-
</section>
44+
- [$x version]([% top %]docs/man$x/man$s/$b.html)
5345
EOF
54-
fi
55-
) > docs/man$r/man$s/$b.cross
56-
fi
46+
done
47+
fi
48+
) > docs/man$r/man$s/$b.cross
5749
done
5850
done
5951
echo >&2

bin/mk-manpages renamed to bin/mk-manpagetts

Lines changed: 48 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -64,83 +64,49 @@ sub main {
6464
print $fh $out or $class->die("Can't print $outinc: $!");
6565
close($fh) or $class->die("Can't close $outinc: $!");
6666

67-
my @htmlnames =
67+
my @mdttnames =
6868
map { (my $x = $_) =~ s|/|-|g; $x } @{$data{names}};
6969
# Older OpenSSL pods have file names that do not correspond
7070
# to any of the names in the NAME section.
7171
# Strictly speaking, we shouldn't use that name, but HTML
7272
# pages with that name have been produced in the past, so
7373
# we keep doing so as long as it's relevant.
74-
if (! grep { $_ eq $origbase } @htmlnames) {
75-
push @htmlnames, $origbase;
74+
if (! grep { $_ eq $origbase } @mdttnames) {
75+
push @mdttnames, $origbase;
7676
}
77-
foreach my $htmlname (@htmlnames) {
78-
my $htmlfile = File::Spec->catdir( "man$data{sectnum}",
79-
"$htmlname.html" );
80-
my $outhtml = File::Spec->catfile( $wwwdir, $htmlfile );
81-
$out = $class->genhtml( $release, $title, $origbase,
82-
$htmlname, %data );
83-
open( $fh, ">", $outhtml )
84-
or $class->die("Can't open $outhtml: $!");
85-
print $fh $out or $class->die("Can't print $outhtml: $!");
86-
close($fh) or $class->die("Can't close $outhtml: $!");
77+
foreach my $mdttname (@mdttnames) {
78+
my $mdttfile = File::Spec->catdir( "man$data{sectnum}",
79+
"$mdttname.md.tt" );
80+
my $outmdtt = File::Spec->catfile( $wwwdir, $mdttfile );
81+
$out = $class->genmdtt( $release, $title, $origbase,
82+
$mdttname, %data );
83+
open( $fh, ">", $outmdtt )
84+
or $class->die("Can't open $outmdtt: $!");
85+
print $fh $out or $class->die("Can't print $outmdtt: $!");
86+
close($fh) or $class->die("Can't close $outmdtt: $!");
8787
}
8888
}
8989
}
9090
}
9191
}
9292

93-
# Generate manpag HTML wrapper
94-
sub genhtml {
95-
my ( $class, $release, $title, $origbase, $htmlbase, %data ) = @_;
93+
# Generate manpage markdown template wrapper
94+
sub genmdtt {
95+
my ( $class, $release, $title, $origbase, $mdttbase, %data ) = @_;
96+
# Note that the .inc file is pure HTML.
97+
# That's OK, markdown can include HTML, by definition.
9698
return <<EOH;
97-
<!DOCTYPE html>
98-
<html lang="en">
99-
<!-- OSSL: original subdir: $data{subdir} -->
100-
<!-- OSSL: subdir: man$data{sectnum} -->
101-
<!-- OSSL: section: $data{sectnum} -->
102-
<!-- OSSL: description: $data{description} -->
103-
<!--#include virtual="/inc/head.shtml" -->
104-
<body>
105-
<!--#include virtual="/inc/banner.shtml" -->
106-
<div id="main">
107-
<div id="content">
108-
<div class="blog-index">
109-
<article>
110-
<header><h2>$title</h2></header>
111-
<div class="entry-content">
112-
<p>
113-
<!--#include virtual="$origbase.inc" -->
114-
</p>
115-
</div>
116-
<footer>
117-
You are here: <a href="/">Home</a>
118-
: <a href="/docs">Docs</a>
119-
: <a href="/docs/manpages.html">Manpages</a>
120-
: <a href="/docs/man$release/">$release</a>
121-
: <a href="/docs/man$release/man$data{sectnum}">man$data{sectnum}</a>
122-
: <a href="/docs/man$release/man$data{sectnum}/$htmlbase.html">$htmlbase</a>
123-
<br/><a href="/sitemap.txt">Sitemap</a>
124-
</footer>
125-
</article>
126-
</div>
127-
<aside class="sidebar">
128-
<section>
129-
<h1><a href="/docs/man$release/">$release manpages</a></h1>
130-
<ul>
131-
<li><a href="../man1">Commands</a></li>
132-
<li><a href="../man3">Libraries</a></li>
133-
<li><a href="../man5">File Formats</a></li>
134-
<li><a href="../man7">Overviews</a></li>
135-
</ul>
136-
</section>
137-
<!--#include virtual="$htmlbase.cross" -->
138-
</aside>
139-
</div>
140-
</div>
141-
<!--#include virtual="/inc/footer.shtml" -->
142-
</body>
143-
</html>
99+
---
100+
OSSL-original-subdir: $data{subdir}
101+
OSSL-subdir: man$data{sectnum}
102+
OSSL-section: $data{sectnum}
103+
OSSL-description: "$data{description}"
104+
breadcrumb: $mdttbase
105+
[% INCLUDE "$mdttbase.cross" %]
106+
---
107+
## $title
108+
109+
[% INCLUDE "$origbase.inc" %]
144110
EOH
145111
}
146112

@@ -263,34 +229,44 @@ __END__
263229
264230
=head1 NAME
265231
266-
mk-manpages - htmlize man pages from POD for the OpenSSL website
232+
mk-manpagetts - man pages from POD into markdown/html templates
267233
268234
=head1 SYNOPSIS
269235
270-
mk-manpages [options] <SrcDir> <RelVer> <WwwDir>
236+
mk-manpagetts [options] <SrcDir> <RelVer> <WwwDir>
271237
272238
<SrcDir> doc directory of release <RelVer>, example 'OpenSSL_1_0_2-stable/doc'
273239
<RelVer> version number associated with <SrcDir>, example '1.0.2'
274-
<WwwDir> top level directory beneath which generated html is stored, example 'web'
240+
<WwwDir> top level directory beneath which generated template is stored,
241+
example 'web'
275242
276243
--help display a brief help message
277244
--man display full documentation
278245
246+
This script is only useful with pre-3.0 OpenSSL. For OpenSSL 3.0 and on,
247+
please use mk-manpagetts3.
248+
279249
=head1 DESCRIPTION
280250
281-
This utility is run on a web server generate the htmlized version of
282-
OpenSSL documentation from the original POD. The resultant directory
251+
This utility is run on a web server generate the markdown/html template version
252+
of OpenSSL documentation from the original POD. The resultant directory
283253
structure may look something like the following (where the contents of
284254
index.html do not come from this tool):
285255
286256
$ ls some/path/to/web
287257
man1.0.2 man1.1.0 manmaster
288258
$ ls some/path/to/web/man1.0.2
289-
apps crypto index.html ssl
259+
index.html man1 man3 man5 man7
290260
$ ls some/path/to/web/man1.0.2/apps
291-
CA.pl.html
292-
asn1parse.html
293-
c_rehash.html
261+
CA.pl.md.tt
262+
asn1parse.md.tt
263+
c_rehash.md.tt
294264
...
295265
266+
The result needs further processing by other tools. Among others, the .md.tt
267+
files rely on the presence of a corresponding .cross file, which is usually
268+
produced later, when all .md.tt files are in place. To finish everything off,
269+
the .md.tt files need to be passed through C<tpage>, and the resulting markdown
270+
must be converted into pure html with a well chosen tool.
271+
296272
=cut

0 commit comments

Comments
 (0)