libei/doc/protocol/generate-protocol-docs.sh
Peter Hutterer 2cf6df9cd0 meson: hook up the protocol documentation via meson
Since we want the generated documentation to be useful on-disk, drop the
baseURL and switch to relativeURLs = true for hugo.

This is arguably a bit nasty in that it git clones the theme into the
build directory. But oh well...
2023-03-07 14:14:58 +10:00

106 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
#
set -e
REPO_BASE_DIR="$PWD"
OUTDIR="$PWD"
SITENAME="ei"
while [[ $# -gt 0 ]]; do
case "$1" in
--verbose | -v)
set -x
shift
;;
--scanner)
SCANNER="$2"
shift 2;
;;
--protocol)
PROTOFILE="$2"
shift 2
;;
--template-dir)
TEMPLATEDIR="$2"
shift 2
;;
--output-dir)
OUTDIR="$2"
shift 2
;;
--index-page)
INDEXPAGE="$2"
shift 2;
;;
--git-repo)
REPO_BASE_DIR="$2"
shift 2;
;;
**)
echo "Unknown argument: $1"
exit 1
;;
esac
done
if [[ -z "$SCANNER" ]]; then
SCANNER="$REPO_BASE_DIR/proto/ei-scanner"
fi
if [[ -z "$PROTOFILE" ]]; then
PROTOFILE="$REPO_BASE_DIR/proto/protocol.xml"
fi
if [[ -z "$TEMPLATEDIR" ]]; then
TEMPLATEDIR="$REPO_BASE_DIR/doc/protocol/"
fi
if [[ -z "$INDEXPAGE" ]]; then
INDEXPAGE="$REPO_BASE_DIR/README.md"
fi
SITEDIR="$OUTDIR/$SITENAME"
if [[ -e "$SITEDIR" ]]; then
echo "$SITEDIR already exists, updating"
else
hugo new site "$SITEDIR"
git clone --depth=1 https://github.com/McShelby/hugo-theme-relearn "$SITEDIR/themes/hugo-theme-relearn"
fi
cp "$TEMPLATEDIR/config.toml" "$SITEDIR/"
if [[ -n "$INDEXPAGE" ]]; then
cp "$INDEXPAGE" "$SITEDIR/content/_index.md"
fi
pushd "$SITEDIR" > /dev/null || exit 1
# Generate a list of available interfaces and read that
# list line-by-line to generate a separate .md file
# for each interface
mkdir -p "$SITEDIR/content/interfaces"
while read -r iface; do
$SCANNER --component=ei --jinja-extra-data="{ \"interface\": \"$iface\" }" --output="$SITEDIR/content/interfaces/$iface.md" "$PROTOFILE" "$TEMPLATEDIR/interface.md.tmpl"
done < <($SCANNER --component=ei "$PROTOFILE" - <<EOF
{% for interface in interfaces %}
{{interface.name}}
{% endfor %}
EOF
)
# Generate a list of available chapters and read that
# list line-by-line to generate a separate .md file
# for each chapter
mkdir -p "$SITEDIR/content/doc"
while read -r title; do
$SCANNER --component=ei --jinja-extra-data="{ \"title\": \"$title\" }" --output="$SITEDIR/content/doc/$title.md" "$PROTOFILE" "$TEMPLATEDIR/chapter.md.tmpl"
done < <($SCANNER --component=ei "$PROTOFILE" - <<EOF
{% for chapter in documentation.chapters %}
{{chapter.title}}
{% endfor %}
EOF
)
hugo
popd > /dev/null || exit 1