-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·118 lines (101 loc) · 3.43 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env bash
set -euxo pipefail
export BIN_DIR=_bin
export OUTPUT_DIR=_site
mkdir -p ${BIN_DIR}
# Avoid removing the output directory itself: this screws with hot reload.
rm -rf ${OUTPUT_DIR}/*
mkdir -p ${OUTPUT_DIR}
##############################################################################
# #
# Auto-download pandoc and dart-sass CLIs #
# #
##############################################################################
case "$(uname -sm)" in
"Darwin arm64")
PANDOC_OS_ARCH_PKG="arm64-macos.zip"
SASS_OS_ARCH="macos-arm64"
;;
"Linux x86_64")
PANDOC_OS_ARCH_PKG="linux-amd64.tar.gz"
SASS_OS_ARCH="linux-x64"
;;
*)
echo "Unrecognized platform"
exit 2
;;
esac
if [ ! -e "${BIN_DIR}/pandoc-${PANDOC_OS_ARCH_PKG}" ]
then
curl \
-L https://github.com/jgm/pandoc/releases/download/3.1.9/pandoc-3.1.9-${PANDOC_OS_ARCH_PKG} \
-o "${BIN_DIR}/pandoc-${PANDOC_OS_ARCH_PKG}"
case "${PANDOC_OS_ARCH_PKG}" in
*.tar.gz)
tar xf "${BIN_DIR}/pandoc-${PANDOC_OS_ARCH_PKG}" -C "${BIN_DIR}"
;;
*.zip)
unzip "${BIN_DIR}/pandoc-${PANDOC_OS_ARCH_PKG}" -d "${BIN_DIR}"
;;
*)
echo "Failed to unpack pandoc"
exit 2
;;
esac
fi
case "${PANDOC_OS_ARCH_PKG}" in
*.tar.gz)
export PANDOC_CLI="$(pwd)/${BIN_DIR}/pandoc-3.1.9/bin/pandoc"
;;
*.zip)
export PANDOC_CLI="$(pwd)/${BIN_DIR}/pandoc-3.1.9-arm64/bin/pandoc"
;;
*)
echo "Failed to resolve pandoc"
exit 2
;;
esac
if [ ! -e "${BIN_DIR}/dart-sass-${SASS_OS_ARCH}.tar.gz" ]
then
curl \
-L https://github.com/sass/dart-sass/releases/download/1.69.5/dart-sass-1.69.5-${SASS_OS_ARCH}.tar.gz \
-o "${BIN_DIR}/dart-sass-${SASS_OS_ARCH}.tar.gz"
tar xf "${BIN_DIR}/dart-sass-${SASS_OS_ARCH}.tar.gz" -C "${BIN_DIR}"
fi
export SASS_CLI="$(pwd)/${BIN_DIR}/dart-sass/sass"
##############################################################################
# #
# Build all assets #
# #
##############################################################################
# Everything in root assets used to be at the root of the repo. Keeping it that
# way for backwards compatibility, just in case there's a reason I wanted them
# there that I forgot about.
cp root-assets/* $OUTPUT_DIR/
# Create an assets/ dir in the outputs.
cp -R assets/ $OUTPUT_DIR/
$SASS_CLI scss/:$OUTPUT_DIR/css/
function pandoc {
$PANDOC_CLI --verbose --standalone --from gfm --to html --mathjax \
--template lib/template.html --metadata-file lib/metadata.yaml $@
}
pandoc --lua-filter lib/index.lua pages/index.md >$OUTPUT_DIR/index.html
ls pages/ | sed "s/.md//" | grep -v index | \
while read path
do
mkdir -p "${OUTPUT_DIR}/${path}"
pandoc "pages/${path}.md" | tee \
"${OUTPUT_DIR}/${path}.html" \
"${OUTPUT_DIR}/${path}/index.html" \
>/dev/null
done
ls posts/ | sed "s/.md//" | \
while read path
do
mkdir -p "${OUTPUT_DIR}/${path}"
pandoc --metadata="basepath:${path}" --lua-filter lib/post.lua \
"posts/${path}.md" | tee \
"${OUTPUT_DIR}/${path}.html" \
"${OUTPUT_DIR}/${path}/index.html" \
>/dev/null
done