blob: 121955eab04bdef7b4a867eef7f165aba915fd78 (
plain)
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
|
#!/usr/bin/env bash
redo-ifchange "$2/title"
extracttitle() {
runhaskell -package-conf=$(find ../.cabal-sandbox -maxdepth 1 -iname '*.conf.d' | head -n 1) ../build/extract-title.hs $@ 2>&1 | grep 'title: ' | cut -d ' ' -f '2-'
}
POSTS=()
while read -r -d $'\0'; do
post=$(realpath --relative-to=. "$REPLY")
POSTS+=("$post")
done < <(find "$2" -maxdepth 1 -mindepth 1 -not -name 'title' -not -name 'preview' -print0 | sort -z)
for x in "${POSTS[@]}"; do
printf "%s\0%s\0" "$x" "${x%.md}.html"
done | xargs -r -0 redo-ifchange
TITLE=$(< $2/title)
cat <<EOF
% $(< "$2/title")
EOF
POST_TITLES=()
for x in "${POSTS[@]}"; do
title=$(pandoc -t json "$x" | extracttitle)
POST_TITLES+=("$title")
done
for n in $(seq 0 $((${#POSTS[@]}-1))); do
printf "* [%s](%s)\n" "${POST_TITLES[$n]}" "${POSTS[$n]%.md}.html"
done
>"$2/preview"
prev_no=3
if [[ ${#POSTS[@]} -gt $prev_no ]]; then
printf "* …\n" >> "$2/preview"
else
prev_no=${#POSTS[@]}
fi
for n in $(seq $prev_no -1 1); do
printf "* [%s](%s)\n" "${POST_TITLES[-$n]}" "${POSTS[-$n]%.md}.html" >>"$2/preview"
done
|