blob: 9c33eda4c4e40343455a8f73eb44a544aace2e3a (
plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#!/bin/bash
# I hereby place this script is in the public domain. - Garrett D'Amore <garrett@damore.org> Jan 23, 2020.
# Usage:
#
# pubrefman.sh <version>
#
# This will checkout the named version (which may be "master" for tip), run asciidoctor over the files,
# prepend standard boilerplate to them, and ...
ver=$1
if [ "${ver}" == "" ]; then
ver=tip
tag=master
else
tag=${ver}
fi
scratch=$(mktemp -d --tmpdir pubrefmanXXXXXX)
trap "rm -rf ${scratch}" 0
repo=$(dirname $0)/..
giturl=https://github.com/nanomsg/nng
# checkout the repo
git clone -q ${giturl} ${scratch}/nng
(cd ${scratch}/nng; git checkout -q $tag)
mkdir ${scratch}/html
mkdir ${scratch}/adoc
cp ${scratch}/nng/docs/man/*.adoc ${scratch}/adoc
getdesc() {
typeset input=$1
typeset -i doname=0
typeset line
while read line
do
case "$line" in
"== NAME")
doname=1
;;
"=="*)
doname=0
;;
"//*"|"")
;;
*" - "*)
if (( doname ))
then
echo ${line#*- }
return
fi
;;
esac
done < ${input}
}
asciidoctor \
-q \
-dmanpage \
-amansource="NNG" \
-amanmanual="NNG Reference Manual" \
-anofooter=yes \
-atoc=left \
-aicons=font \
-asource-highlighter=pygments \
-alinkcss \
-bhtml5 \
-D ${scratch}/html \
${scratch}/adoc/*.adoc
typeset -A descs
typeset -A pages
for f in ${scratch}/adoc/*.adoc; do
src=${f##*/}
sect=${src%.adoc}
sect=${sect##*.}
pages[${sect}]="${pages[${sect}]} ${src}"
descs[${src}]=$(getdesc $f)
done
index=${scratch}/adoc/index.adoc
for sect in $(echo ${!pages[@]} | tr " " "\n" | sort ); do
title=$(cat ${scratch}/nng/docs/man/man${sect}.sect)
desc=$(cat ${scratch}/nng/docs/man/man${sect}.desc)
printf "\n== Section ${sect}: ${title}\n" >> ${index}
printf "\n${desc}\n" >> ${index}
printf "\n[cols=\"3,5\"]\n" >> ${index}
printf "|===\n" >> ${index}
for page in $(echo ${pages[$sect]} | tr " " "\n" | sort ); do
name=${page%.adoc}
name=${name%.*}
printf "|xref:${page}[${name}(${sect})]\n" >> ${index}
printf "|${descs[${page}]}\n\n" >> ${index}
done
printf "|===\n" >> ${index}
done
asciidoctor \
-q \
-darticle \
-anofooter=yes \
-atoc=left \
-alinkcss \
-bhtml5 \
-D ${scratch}/html \
${scratch}/adoc/index.adoc
dest=${repo}/man/${ver}
mkdir -p ${dest}
add=""
for f in ${scratch}/html/*; do
# insert the header - HTML only
case $f in
*.html)
printf "--" "---\nversion: ${ver}\nlayout: refman\n---\n" > ${f}.new
cat ${f} >> ${f}.new
mv ${f}.new ${f}
;;
*.css)
;;
esac
base=${f##*/}
cp $f ${dest}/${base}
add="${add} ${dest}/${base}"
done
git add ${add}
for f in ${dest}/*; do
base=${f##*/}
if [ ! -f ${scratch}/html/${base} ]; then
echo "removing ${f} (not in ${scratch}/html/${base})"
git rm ${f}
fi
done
git commit -q -m "Publishing updates for ${ver}"
printf "A final push should be done once changes are verified.\n"
|