-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-site
More file actions
executable file
·51 lines (41 loc) · 1.07 KB
/
build-site
File metadata and controls
executable file
·51 lines (41 loc) · 1.07 KB
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
#!/usr/bin/env bash
die () { printf 'fatal: %b\n' "$@" >&2; exit 1; }
first_line_of_file () {
mapfile -tn 1 line < "$1"
printf '%s\n' "${line[@]}"
}
build_page () {
filename=${1##*/}
html="${filename/%.md/.html}"
[[ $html -ot $1 ]] || return
printf '%s\n' " GEN ${html}"
if [[ $html != index.html ]]; then
header="<a href='index.html'>Home</a>"
fi
first_line="$(first_line_of_file $1)"
# The first line of a man page in markdown starts with a % character
[[ $first_line == *%* ]] && header="${header}<br>${first_line#%}"
printf '%b' "${template/'{{content}}'/$header$(pandoc "$1")}" >"${html}"
header=
}
build_src_pages () {
template="$(<"src/template.html")"
for md in src/*.md; do
build_page "${md}"
done
}
build_man_pages () {
if ! [[ -d ../jgmenu ]]; then
printf 'warn: %b\n' "Need jgmenu next to jgmenu.github.io to build man pages" >&2
return
fi
template="$(sed -e 's/sans-serif/monospace/' src/template.html)"
for md in ../jgmenu/docs/manual/*.md; do
build_page "${md}"
done
}
main () {
build_src_pages
build_man_pages
}
main "$@"