Skip to content

Commit 8fa7f3a

Browse files
Document man page sync with the new website
1 parent 242b224 commit 8fa7f3a

File tree

3 files changed

+123
-3
lines changed

3 files changed

+123
-3
lines changed

deps/rabbit/docs/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.html
2+
*.md
3+

deps/rabbit/docs/README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,24 @@ This directory contains [CLI tools](https://rabbitmq.com/docs/cli/) man page sou
99
Please [see rabbitmq.com](https://rabbitmq.com/docs/) for documentation guides.
1010

1111

12+
## man Pages
1213

14+
### Dependencies
1315

14-
## man Pages
16+
* `man`
17+
* [`tidy5`](https://binaries.html-tidy.org/) (a.k.a. `tidy-html5`)
18+
19+
On macOS, `tidy5` can be installed with Homebrew:
20+
21+
``` shell
22+
brew install tidy-html5
23+
```
24+
25+
and then be found under the `bin` directory of the Homebrew cellar:
26+
27+
``` shell
28+
/opt/homebrew/bin/tidy --help
29+
```
1530

1631
### Source Files
1732

@@ -25,14 +40,24 @@ man docs/rabbitmq-diagnostics.8
2540
man docs/rabbitmq-queues.8
2641
```
2742

28-
2943
To converted all man pages to HTML using `mandoc`:
3044

3145
``` shell
3246
gmake web-manpages
3347
```
3448

35-
The result is then copied to the [website repository](https://github.com/rabbitmq/rabbitmq-website/tree/live/site/man)
49+
The result then must be post-processed and copied to the website repository:
50+
51+
``` shell
52+
# cd deps/rabbit/docs
53+
#
54+
# clear all generated HTML and Markdown files
55+
rm *.html *.md
56+
# export tidy5 path
57+
export TIDY5_BIN=/opt/homebrew/bin/tidy;
58+
# run the post-processing script, in this case it updates the 3.13.x version of the docs
59+
./postprocess_man_html.sh . /path/to/rabbitmq-website.git/versioned_docs/version-3.13/man/
60+
```
3661

3762
### Contributions
3863

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
srcdir="$1"
6+
destdir="$2"
7+
8+
tidy_bin=${TIDY5_BIN:-"tidy5"}
9+
10+
for src in "$srcdir"/*.html; do
11+
name=$(basename "$src" .html)
12+
dest="$destdir/$name.md"
13+
echo "src=$src" "dest=$dest" "name=$name"
14+
15+
cat <<EOF > "$dest"
16+
---
17+
title: $name
18+
---
19+
EOF
20+
21+
$tidy_bin -i --wrap 0 \
22+
--asxhtml \
23+
--show-body-only yes \
24+
--drop-empty-elements yes \
25+
--drop-empty-paras yes \
26+
--enclose-block-text yes \
27+
--enclose-text yes "$src" \
28+
| \
29+
awk '
30+
/<h[1-6]/ {
31+
if ($0 ~ /<h1/) {
32+
level = "#";
33+
} else if ($0 ~ /<h2/) {
34+
level = "##";
35+
} else if ($0 ~ /<h2/) {
36+
level = "##";
37+
} else if ($0 ~ /<h3/) {
38+
level = "###";
39+
} else if ($0 ~ /<h4/) {
40+
level = "####";
41+
} else if ($0 ~ /<h5/) {
42+
level = "#####";
43+
} else if ($0 ~ /<h6/) {
44+
level = "######";
45+
}
46+
47+
id = $0;
48+
sub(/.*(id|name)="/, "", id);
49+
sub(/".*/, "", id);
50+
51+
title = $0;
52+
sub(/ *<\/.*/, "", title);
53+
sub(/.*> */, "", title);
54+
55+
print level, title, "{#" id "}";
56+
next;
57+
}
58+
/dt id="/ {
59+
id = $0;
60+
sub(/.*(id|name)="/, "", id);
61+
sub(/".*/, "", id);
62+
63+
line = $0;
64+
sub(/id="[^"]*"/, "", line);
65+
print line;
66+
67+
next;
68+
}
69+
/a class="permalink"/ {
70+
title = $0;
71+
sub(/ *<a [^>]*>/, "", title);
72+
sub(/<\/a>/, "", title);
73+
sub(/<br[^>]*>/, "", title);
74+
gsub(/>\*</, ">\\&ast;<", title);
75+
76+
print level "#", title, "{#" id "}";
77+
next;
78+
}
79+
{
80+
line = $0;
81+
gsub(/{/, "\\&lcub;", line);
82+
gsub(/<li>/, "<li>\n", line);
83+
gsub(/<\/li>/, "\n</li>", line);
84+
gsub(/<\/ul>/, "</ul>\n", line);
85+
gsub(/<br[^>]*>/, "<br\/>", line);
86+
gsub(/<\/div>]/, "<\/div>\n]", line);
87+
gsub(/style="[^"]*"/, "", line);
88+
print line;
89+
next;
90+
}
91+
' > "$dest"
92+
done

0 commit comments

Comments
 (0)