-
Notifications
You must be signed in to change notification settings - Fork 19
/
build.sh
executable file
·87 lines (70 loc) · 2.16 KB
/
build.sh
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
set -o errexit
set -o errtrace
set -o nounset
# shellcheck disable=SC2154
trap '_es=${?};
_lo=${LINENO};
_co=${BASH_COMMAND};
echo "${0}: line ${_lo}: \"${_co}\" exited with a status of ${_es}";
exit ${_es}' ERR
# https://en.wikipedia.org/wiki/ANSI_escape_code
E0="$(printf "\e[0m")" # reset
E30="$(printf "\e[30m")" # black foreground
E97="$(printf "\e[97m")" # bright white foreground
E100="$(printf "\e[100m")" # bright black (gray) background
E107="$(printf "\e[107m")" # bright white background
#### FUNCTIONS ################################################################
header() {
# Print 80 character wide black on white heading with time
printf "${E30}${E107} %-71s$(date '+%T') ${E0}\n" "${@}"
}
pandoc_with_options() {
local _input _lang _output _title _toc_title
_input="${1}"
_lang="${2}"
_title="${3}"
_toc_title="${4}"
_output="${5}"
_mod_date="$(TZ=UTC date -r "${_input}" '+%F %T %Z')"
print_var _input
print_var _lang
print_var _title
print_var _toc_title
print_var _output
print_var _mod_date
# pandoc options are ordered the same as: https://pandoc.org/MANUAL.html
pandoc \
--from markdown \
--to html5 \
--output "${_output}" \
--verbose \
--metadata lang="${_lang}" \
--metadata title="${_title}" \
--template template.html \
--variable lastmodified:"${_mod_date}" \
--variable toc_title:"${_toc_title}" \
--eol=lf \
--wrap=auto \
--columns=79 \
--toc \
--toc-depth 4 \
--ascii \
--email-obfuscation javascript \
"${_input}"
}
print_key_val() {
printf "${E97}${E100}%12s${E0} %s\n" "${1}:" "${2}"
}
print_var() {
print_key_val "${1}" "${!1}"
}
#### MAIN #####################################################################
header 'Building English FAQ HTML'
pandoc_with_options faq-en.md en-US 'Frequently Asked Questions' \
'Table of contents' faq/index.html
echo
header 'Building French FAQ HTML'
pandoc_with_options faq-fr.md fr 'Foire Aux Questions' 'Table des matières' \
faq/fr/index.html
echo