summaryrefslogtreecommitdiff
path: root/build-docs
blob: a3a1dc91841604e0546892dbc69a8e4c32fffd49 (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
#!/bin/bash

set -euo pipefail

# Get output directory.
if [ "$#" != 1 ]; then
	echo "Usage: $0 OUTPUT-DIR" 1>&2
	exit 1
fi
output="$1"

# Build Subplot so that we can use it to generate
# documentation.

cargo build
PATH="${CARGO_TARGET_DIR:-target}:$PATH"
type -all subplot

# Build subplots that come with Subplot

opts="--resources $(pwd)/src/share"
find . -name "*.subplot" |
	grep -Fv .gitlab/ |
	while read -r file; do
		base="$(basename "$file" .subplot)"
		(
			cd "$(dirname "$file")"
			# shellcheck disable=SC2154 disable=SC2086
			if subplot $opts metadata --merciful "$base.subplot" | awk '/^title:/ && NF > 1' | grep .; then
				subplot $opts docgen --merciful "$base.subplot" -o "$output/$base.html"
			fi
		)
	done

# Build Subplot library documentation.

libdocs="$output/libdocs"
mkdir -p "$libdocs"

find share -name '*.yaml' ! -name template.yaml |
	while read -r yaml; do
		dir="$(dirname "$yaml")"
		md="$dir/$(basename "$yaml" .yaml).md"
		subplot "--resources=$(pwd)" libdocgen --output "$md" "$yaml"
		pandoc --standalone --self-contained \
			--metadata title="$(basename "$yaml" .yaml)" \
			-o "$libdocs/$(basename "$md" .md)".html "$md"
	done