-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsite-generate
executable file
·48 lines (36 loc) · 1.3 KB
/
website-generate
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
#!/usr/bin/env bash
#
# Generate HTML from markdown files, and copy resources,
# to produce a complete website.
set -o errexit -o nounset -o pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
declare -r SCRIPT_DIR
declare -r WEBSITE="${1:-}"
if [[ -z "${WEBSITE}" ]]; then
echo >&2 "Usage: $0 <website>"
exit 1
fi
declare -r WEBSITE_MARKDOWN="${SCRIPT_DIR}/${WEBSITE%%\.*}.markdown"
declare -r WEBSITE_HTML="${SCRIPT_DIR}/${WEBSITE}"
declare -r DATA_DIR="${WEBSITE_MARKDOWN}/pandocomatic"
declare -r INPUT_DIR="${WEBSITE_MARKDOWN}/content"
declare -r OUTPUT_DIR="${WEBSITE_HTML}"
declare -r RESOURCES_DIR="${WEBSITE_MARKDOWN}/resources"
echo >&2 "Generating [${WEBSITE}]"
start_time="$(date +%s)"
declare -r start_time
# Copy all resources to output, and delete anything in output that
# is not in resources - this will remove any generated HTML, which
# is OK (and preferred) b/c we're going to generate fresh HTML next.
rsync -a --delete "${RESOURCES_DIR}/" "${OUTPUT_DIR}/"
# Generate fresh HTML from the markdown files.
pandocomatic \
--quiet \
--data-dir "${DATA_DIR}" \
--input "${INPUT_DIR}" \
--output "${OUTPUT_DIR}"
end_time="$(date +%s)"
declare -r end_time
((elapsed_time = end_time - start_time))
declare -r elapsed_time
echo "Website updated in [${elapsed_time}] seconds"