blob: df3cec4677e82e8b0558e797056b672ce7c5fa48 (
plain) (
blame)
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
|
#!/bin/env bash
set -e
mkdir -p pub/priv
rm -f res/diag/*
mkdir -p res/diag
cp index.md pub/index.md
cp index.md pub/priv/index.md
printf "\n\n" >>pub/index.md
printf "\n\n" >>pub/priv/index.md
export MERMAID_FILTER_FORMAT="svg"
export MERMAID_FILTER_THEME="dark"
export MERMAID_FILTER_BACKGROUND="transparent"
export MERMAID_FILTER_LOC="res/diag"
export MERMAID_FILTER_IMAGE_CLASS="mermaid"
ARGS="-A common.html -F mermaid-filter --toc --css style.css -t html -s --citeproc --bibliography=bib.bib --biblatex -L ./server-katex/filter.lua"
NHEAD=13
function generate_index() {
pandoc --css index.css --css style.css -A common.html -t html "$1" -s -L ./server-katex/filter.lua -o "$2" &
}
# public
declare -A all_tags
declare -A all_posts
for file in $(ls -1 md/*.md | sort -r); do
EXTRA="-A append.html"
plot="$(head -n$NHEAD "$file" | grep -m 1 plot | cut -c 7-)"
[[ "$plot" = "true" ]] && EXTRA="$EXTRA -A plot.html"
name="$(basename $file | cut -f 1 -d '.')"
title="$(head -n$NHEAD "$file" | grep -m 1 ^title | cut -c 8-)"
tags="$(head -n$NHEAD "$file" | grep -m 1 ^tags | cut -c 7-)"
date="$(echo $name | rev | cut -c 4- | rev)"
pubdate="$(head -n$NHEAD "$file" | grep -m 1 ^date | cut -c 6-)"
author="$(head -n$NHEAD "$file" | grep -m 1 ^author | cut -c 8-)"
count="$(pandoc --lua-filter wordcount.lua "$file")"
if [[ "$tags" == *"essay"* ]]; then
EXTRA=""
fi
pandoc $ARGS $EXTRA "$file" -o "pub/$name".html &
post="- [$title]($name.html)"
# post="$post<div>$date - $pubdate · $count words · $author</div><div class=tags>"
post="$post<div>$pubdate · $count words · $author</div><div class=tags>"
tags="$(echo "$tags" | tr "," "\n")"
while IFS= read -r tag; do
all_tags["$tag"]="$name"$'\n'"${all_tags["$tag"]}"
post="$post<a class=tag href='tag_$tag.html'>$tag</a>"
done <<<"$tags"
post="$post</div>"
all_posts["$name"]="$post"
echo "$post" >>pub/index.md
echo "generated $title"
done
for tag in "${!all_tags[@]}"; do
cp index.md "pub/tag_$tag.md"
for name in ${all_tags[$tag]}; do
echo "${all_posts[$name]}" >>"pub/tag_$tag.md"
done
generate_index "pub/tag_$tag.md" "pub/tag_$tag.html"
done
# private/unfinished
# TODO: Merge with pub code
priv_words=0
priv_count=0
for file in $(ls -1 md-priv/*.md | sort -r); do
EXTRA="-A append.html"
plot="$(head -n$NHEAD "$file" | grep -m 1 plot | cut -c 7-)"
[[ "$plot" = "true" ]] && EXTRA="$EXTRA -A plot.html"
name="$(basename $file | cut -f 1 -d '.')"
pandoc $ARGS $EXTRA "$file" -o "pub/priv/$name".html &
title="$(head -n$NHEAD "$file" | grep -m 1 ^title | cut -c 8-)"
date="$(echo $name | rev | cut -c 4- | rev)"
pubdate="$(head -n$NHEAD "$file" | grep -m 1 ^date | cut -c 6-)"
author="$(head -n$NHEAD "$file" | grep -m 1 ^author | cut -c 8-)"
count="$(pandoc --lua-filter wordcount.lua "$file")"
priv_words=$((priv_words + count))
priv_count=$((priv_count + 1))
# echo "- [$title]($name.html) $date - $pubdate · $count words · $author" >>pub/priv/index.md
echo "- [$title]($name.html) $pubdate · $count words · $author" >>pub/priv/index.md
echo "generated $title"
done
#echo "" >>pub/index.md
#echo "<div class=index-note><p>Queue: Working on $priv_count to-be-published posts, totalling $priv_words words.</p></div>" >>pub/index.md
generate_index pub/index.md pub/index.html
generate_index pub/priv/index.md pub/priv/index.html
echo "waiting..."
for job in $(jobs -p); do
wait "$job" || echo "$job failed"
done
cp *.rss pub/
cp *.css pub/
cp *.css pub/priv/
# cp res/favicon.ico pub/
cp -r res/ pub/
cp -r res/ pub/priv/
echo "done!"
|