aboutsummaryrefslogtreecommitdiff
path: root/aux/workflow/manpages2html.sh
blob: 2498b5c1900e705d017c42584190df1a70746948 (plain) (blame)
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
#!/bin/sh
set -eu

while getopts 'o:' flag; do
	case "$flag" in
		o)
			OUTDIR="$OPTARG"
			;;
		*)
			exit 2
			;;
	esac
done
shift $((OPTIND - 1))

assert_arg() {
	if [ -z "$1" ]; then
		echo "Missing $2" >&2
		exit 2
	fi
}

assert_arg "${OUTDIR:-}" '-o OUTDIR'

for f in "$@"; do
	l="$(echo "$f" | awk -F. '{print $(NF-1)}')"
	n="$(echo "$f" | awk -F. '{print $NF}')"
	to_name="$(basename "${f%."$l"."$n"}.$n.html")"
	mkdir -p "$OUTDIR/$l"
	pandoc \
		--toc                        \
		--toc-depth=2                \
		-s                           \
		-r man                       \
		-w html                      \
		-H aux/workflow/favicon.html \
		-H aux/workflow/style.css    \
		--metadata "lang=$l"         \
		< "$f" > "$OUTDIR/$l/$to_name"
done