-
Notifications
You must be signed in to change notification settings - Fork 34
/
update_libtw2_doc.sh
executable file
·69 lines (58 loc) · 1.77 KB
/
update_libtw2_doc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# dependencies (on debian 10 to keep the diff minimal):
# apt install curl pandoc
URL="/docs/libtw2"
if [ -z "$1" ]; then
OUT_DIR="www/docs/libtw2"
else
OUT_DIR="$1"
fi
function file_names() {
# When adding/removing files, edit www/_data/menus.yml to update the menu
echo connection.md,Connection
echo datafile.md,Datafile
echo demo.md,Demo
echo huffman.md,Huffman
echo int.md,Int
echo map.md,Map
echo packet.md,Packet
echo packet7.md,Packet7
echo protocol.md,Protocol
echo quirks.md,Quirks
echo serverinfo_extended.md,Serverinfo extended
echo snapshot.md,Snapshot
echo teehistorian.md,Teehistorian
}
function import_article() {
local REMOTE_NAME="$1"
local TITLE="$2"
echo "---"
echo "title: \"${TITLE}\""
echo "layout: default"
echo "menu-extern: docs-libtw2"
echo "---"
echo '<div id="global" class="block">'
echo ""
echo "<h2>${TITLE}</h2>"
echo ""
echo "<!-- File imported from https://github.com/heinrich5991/libtw2/blob/master/doc/${REMOTE_NAME}. -->"
echo "<!-- Please create pull requests at https://github.com/heinrich5991/libtw2 if you want to edit this page. -->"
echo ""
echo '<small><i>This file is mirrored from the <a href="https://github.com/heinrich5991/libtw2">libtw2</a> documentation and is dual-licensed under MIT or APACHE.</i></small><br>'
echo ""
curl "https://raw.githubusercontent.com/heinrich5991/libtw2/master/doc/${REMOTE_NAME}" \
| pandoc --from gfm --to commonmark \
| sed 's/^#/###/g' \
| sed "s/(\\(.*\\)\\.md)/(..\/\\1)/g" \
| pandoc --from commonmark --to html \
echo '</div>'
}
mkdir -p "$OUT_DIR"
IFS=','
file_names | while read NAME TITLE
do
FILENAME="${OUT_DIR}/${NAME/.md/}/index.html"
mkdir -p "$(dirname "$FILENAME")"
echo "importing ${NAME} to ${FILENAME}"
import_article $NAME $TITLE > ${FILENAME}
done