From 6dcbaa8539aa974245ab30fba8a2c9576462f40f Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 28 Jan 2020 08:50:21 -0800 Subject: Publishing site updates This converts the NNG site to the new style. Only the master pages are updated -- the individual man pages still need work. --- _tools/publish-nng.sh | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 _tools/publish-nng.sh (limited to '_tools') diff --git a/_tools/publish-nng.sh b/_tools/publish-nng.sh new file mode 100644 index 00000000..b05f839f --- /dev/null +++ b/_tools/publish-nng.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +# I hereby place this script is in the public domain. - Garrett D'Amore Jan 23, 2020. + +# Usage: +# +# publish-nng.sh +# +# 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=${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" -- cgit v1.2.3-70-g09d2