aboutsummaryrefslogtreecommitdiff
path: root/aux/workflow/TODOs.sh
blob: 96cb06499ff3ca071adf1018141013da39af2175 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
set -eu

TLD="$(cat aux/tld.txt)"
PROJECT_UC=
while getopts 'n:N:m:o:' flag; do
	case "$flag" in
		n)
			PROJECT="$OPTARG"
			;;
		N)
			PROJECT_UC="$OPTARG"
			;;
		m)
			MAILING_LIST="$OPTARG"
			;;
		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 "${PROJECT:-}" '-n PROJECT'
assert_arg "${MAILING_LIST:-}" '-m MAILING_LIST'
assert_arg "${OUTDIR:-}" '-o OUTDIR'

if [ -z "${PROJECT_UC:-}" ]; then
	PROJECT_UC="$PROJECT"
fi

TODOS_ADD_REGEX='s/^## (TODO|DOING|WAITING|MEETING|INACTIVE|NEXT|CANCELLED|DONE|WONTFIX) (.*) \{#(.*?)\}(.*)$/## <a href="#\3"><span class="\1">\1<\/span> \2<\/a>\4\n<pre class="header-anchor" id="\3">#\3<\/pre>\n/'
TAGS_REGEX='s/tag:([\w-]+)/<span class="tag">\1<\/span>/g'
TODOS_CLEANUP_REGEX1='s/(<a><a)/<a/'
TODOS_CLEANUP_REGEX2='s/<\/a><\/a>/<\/a>/'

sed -e "s:@PROJECT_UC@:$PROJECT_UC:g"     \
    -e "s:@PROJECT@:$PROJECT:g"           \
    -e "s:@MAILING_LIST@:$MAILING_LIST:g" \
    -e "s:@TLD@:$TLD:g"                   \
    < aux/workflow/preamble.md | \
	printf \
		'%s\n\n' \
		"$(cat - TODOs.md)" | \
	perl -pe "$TODOS_ADD_REGEX" | \
	perl -pe "$TAGS_REGEX"      | \
	pandoc \
		--toc                                  \
		--highlight-style pygments             \
		--toc-depth=2                          \
		-s                                     \
		--metadata title="$PROJECT_UC - TODOs" \
		--metadata lang=en                     \
		-r commonmark                          \
		-w html                                \
		-H aux/workflow/favicon.html           \
		-H aux/workflow/style.css              \
		| \
	perl -pe "$TODOS_CLEANUP_REGEX1" | \
	perl -pe "$TODOS_CLEANUP_REGEX2" \
	> "$OUTDIR/TODOs.html"