summaryrefslogtreecommitdiff
path: root/_tools/publish-nng.sh
blob: b05f839f17d9a7d73b8f20f260f5f90e0a9f73ab (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
#!/bin/bash

# I hereby place this script is in the public domain. - Garrett D'Amore <garrett@damore.org>  Jan 23, 2020.

# Usage:
#
# publish-nng.sh <version>
#
# This publishes content from the _adoc directory into the main tree.  Individual files can be specified.
# It runs asciidoctor over the files, and massages them.

if [[ $# -gt 0 ]]
then
	files=$*
	echo "using user specified args ${files[@]}"
else
	files=$( find ../_adoc/ -type f -name '*.adoc' )
	echo "finding files ${files[@]}"
fi

scratch=$(mktemp -d --tmpdir pubnngXXXXXX)
trap "rm -rf ${scratch}" 0
dest=$(dirname $0)/..

for f in ${files[@]}
do
        base=${f##*/_adoc}
        dir=${base%/*}
        base=${base##/}

        asciidoctor \
                -q \
	        -darticle \
	        -anofooter=yes \
                -askip-front-matter \
	        -aicons=font \
	        -asource-highlighter=pygments \
	        -alinkcss \
	        -bhtml5 \
	        -D ${scratch}/${dir} \
                ${f}
done

process_html() {
        typeset skip=yes
        typeset layout=$1
        typeset ver=$2
        typeset title=""
        while read line; do
                # Look for the body tag, so that we strip off all the pointless
                # front matter, because we're going to replace that.   We
                # don't actually emit the body tags.  We also strip out any
                # link tags.
                case "$line" in
                "<title>"*)
                        title=${line#*'>'}
                        title=${title%'<'*}
                        ;;
                "<body"*)
                        printf -- "---\n"
                        printf "layout: ${layout}\n"
                        printf "title: ${title}\n"
                        printf -- "---\n"
                        printf "<main>\n"
                        skip=
                        ;;
                "</body"*)
                        printf "</main>\n"
                        skip=yes
                        ;;
                "<link"*)
                        ;;
                *)
                        if [[ -z "$skip" ]]; then
                                printf "%s\n" "$line"
                        fi
                        ;;
                esac
        done
}

add=""
for f in $(find ${scratch} -name '*.html' ); do

        base=${f##${scratch}}
        base=${base##/}

        # insert the header - HTML only
        process_html nng < ${f} > ${f}.new
        mv ${f}.new ${f}
        cp ${f} ${dest}/${base}
        add="${add} ${dest}/${base}"
done
git add ${add}
git commit -q -m "Publishing site updates"

printf "A final push should be done once changes are verified.\n"