aboutsummaryrefslogtreecommitdiff
path: root/aux/workflow/commonmark.sh
blob: b1968670095f42fa17461e5f743165a065d7da55 (about) (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
set -eu

while getopts 'N:o:r:w:L:' flag; do
	case "$flag" in
		N)
			PROJECT_UC="$OPTARG"
			;;
		o)
			OUTDIR="$OPTARG"
			;;
		r)
			IN_FILE="$OPTARG"
			;;
		w)
			OUT_FILE="$OPTARG"
			;;
		L)
			THE_LANG="$OPTARG"
			;;
		*)
			exit 2
			;;
	esac
done
shift $((OPTIND - 1))

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

assert_arg "${PROJECT_UC:-}" '-N PROJECT_UC'
assert_arg "${OUTDIR:-}"     '-o OUTDIR'
assert_arg "${IN_FILE:-}"    '-i IN_FILE'
assert_arg "${THE_LANG:-}"   '-L THE_LANG'

if [ -z "${OUT_FILE:-}" ]; then
	OUT_FILE="${IN_FILE%.md}.html"
fi

OUT="$OUTDIR/$OUT_FILE"
mkdir -p "$(dirname "$OUT")"

pandoc \
	--toc                                           \
	--highlight-style pygments                      \
	--toc-depth=2                                   \
	-s                                              \
	--metadata title="$PROJECT_UC - ${IN_FILE%%.*}" \
	--metadata "lang=$THE_LANG"                     \
	-r commonmark                                   \
	-w html                                         \
	-H aux/workflow/favicon.html                    \
	< "$IN_FILE" > "$OUT"