-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·73 lines (66 loc) · 1.78 KB
/
build
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
70
71
72
#!/bin/bash
xsltproc --nonet chunk.xsl manual.xml
echo "Extracting:"
echo -ne "\t"
for FILE in feature/*.html guide/*.html; do
ID=${FILE%.html}
echo -n "${ID#*/} "
SECTION="chapter"
[ $FILE = "guide/index.html" ] && SECTION="book"
sed -i 's/.*<html [^>]\+>/<html>/' $FILE
xmlstarlet sel -t -c "//div[@class='$SECTION']" $FILE \
| tidy -q -xml \
| sed '/“$/N;s/\(“\)\n */\1/' \
| sed 's!\(</code>\)\([^- ,:.<]\)!\1 \2!g' \
| sed '/<$/N;s/<\n */\</' \
| sed 's/\([a-zA-Z0-9_”]<[^>]\+>\)\([a-zA-Z0-9_]\)/\1 \2/g' \
| sed 's/\([a-zA-Z0-9_]<[^>]\+>\) \([sd]\)\>/\1\2/g' \
| sed 's/<a id=\([^ ]\+\) \/>/<a id=\1><\/a>/g' \
| sed 's/Chapter [0-9]\+\. //' \
| sed "s/id=\"${ID#*/}-/id=\"/g" \
| sed 's/ \+$//' \
| sed 's!\.\./feature!/feature!' \
| sed 's!\.\./guide!/guide!' \
| sed 's/ *class="table" */ /' \
| sed 's!/feature/\([-a-z]\+\)\.html\(#\)*\(\1-\)*!/feature/\1\2!' \
| sed "s/${FILE#*/}#/#/" \
| sponge $FILE
done
echo
for FILE in feature/*.html; do
sed -i 's/href="\([-a-z]\+\)\.html/href="\/feature\/\1/' $FILE
done
echo "Wrapping:"
echo -ne "\t"
for FILE in feature/*.html; do
ID=${FILE%.html}
echo -n "${ID#*/} "
ID=${ID/\//\\/}
TITLE=$(sed -n "/id=\"$ID\">/s/.*a>\(.*\) Feature.*/\1/p" $FILE)
DESC=$(sed -n '/class="subtitle"/{n;s/ *<[^>]\+>//g;p}' $FILE)
(
echo "---"
echo "title: $TITLE"
echo "description: $DESC"
echo "since: "
echo "status: stable"
echo "---"
echo "{% raw %}"
cat $FILE
echo "{% endraw %}"
) | sponge $FILE
done
for FILE in guide/*.html; do
ID=${FILE%.html}
echo -n "${ID#*/} "
TITLE=$(sed -n -e '/<h1 /{n;p}' $FILE | sed -e 's:</h1.*::' -e 's/.*[;>]//')
(
echo "---"
echo "title: $TITLE"
echo "---"
echo "{% raw %}"
cat $FILE
echo "{% endraw %}"
) | sponge $FILE
done
echo