···11#!/usr/bin/env sh
2233-index_template='template_index.html'
44-page_template='template_page.html'
33+defaults_file='default.json'
44+55template_start='<!--BEGIN TEMPLATE-->'
66template_end='<!--END TEMPLATE-->'
7788-[ -n "${1}" ] && cd "${1}"
99-! [ -e "$index_template" ] && echo "${0}: error: ${1%/}/${index_template} does not exist" >&2 && exit 1
1010-! [ -e "$page_template" ] && echo "${0}: error: ${1%/}/${page_template} does not exist" >&2 && exit 1
88+rel_root=''
99+[ -n "${1:+x}" ] && cd "${1}" && rel_root="${1%/}/"
1010+! [ -e "$defaults_file" ] && echo "${0}: error: ${rel_root}${defaults_file} does not exist" && exit 1
1111+defaults="$(jq -c '.' "$defaults_file")"
1212+1313+index_template="$(jq -r '.["$index-template"]' <<<"$defaults")"
1414+! [ -e "$index_template" ] && echo "${0}: error: ${rel_root}${index_template} does not exist" >&2 && exit 1
11151216# generate the code syntax highlighting css
1317# unfortunately pandoc did not like --template=<(echo ...)
···2832# this... thing turns the template in the html into a json string with jq string interpolation, to be passed back into jq
2933# thankfully this only has to be done once. cursedd
3034template="$(sed "/\s*${template_start}/,/\s*${template_end}/!d;//d" "${index_template}" | \
3131- jq -Rs '"\"" + (gsub("(?<s>^|}})(?<p>.+?)(?<e>{{|$)"; "\(.s + (.p|@json|trimstr("\"")) + .e)"; "m") | rtrim | gsub("{{(?<p>.+?)}}"; "\\(\(.p))"; "m")) + "\""' -r)"
3535+ jq -Rrs '"\"" + (gsub("(?<s>^|}})(?<p>.+?)(?<e>{{|$)"; "\(.s + (.p|@json|trimstr("\"")) + .e)"; "m") | rtrim | gsub("{{(?<p>.+?)}}"; "\\(\(.p))"; "m")) + "\""')"
32363333-find . -name content.djot -print0 | sort -r -z | while read -r -d '' post; do
3737+find . -name meta.json -print0 | sort -r -z | while read -r -d '' post; do
3438 post="${post%/*}"
3539 echo -n "${post} "
3640 slashesinpath="${post//[^\/]}" # delete everything that isnt a slash
3741 slashesinpath="${#slashesinpath}" # count whats left (count slashes in $post)
3842 backtoblogroot="$(for ((i=0; i < slashesinpath; i++)); do echo -n '../'; done)"
3943 backtoblogroot="${backtoblogroot%/}"
4040- jq '.title' "${post}/meta.json"
4141- jq -r --arg path "${post}" "${template}" "${post}/meta.json" >> ./index.html
4242- pandoc -f djot -t html5 \
4343- --mathml \
4444- --template="${page_template}" \
4545- --variable="backtoblogroot=${backtoblogroot}" \
4444+4545+ # this thing is responsible for concatenating arrays together if for example both default and meta specify $pandoc-args
4646+ # it also replaces every instance of {{root}} in $pandoc-args with backtoblogroot
4747+ meta="$(jq -c '$meta[0] as $meta | . as $default | $meta | [paths(type == "array")] | reduce .[] as $p ($meta; setpath($p; ($default | getpath($p) // []) + getpath($p))) | $default * . | .["$pandoc-args"] = (.["$pandoc-args"] | map(gsub("{{root}}"; $root)))' \
4848+ --slurpfile meta "${post}/meta.json" --arg root "$backtoblogroot" <<<"$defaults")"
4949+5050+ jq '.title' <<<"$meta"
5151+5252+ # with help from domi https://donotsta.re/objects/b84298d7-582f-4b42-9bbd-bc5636a2b9fb
5353+ pandoc_args=()
5454+ while read -r -d '' arg; do pandoc_args+=("$arg"); done < \
5555+ <(jq --raw-output0 '.["$pandoc-args"][], .["$input"], "-o", .["$output"]' <<<"$meta")
5656+5757+ pushd "$post" >/dev/null
5858+ pandoc_error=0
5959+ pandoc \
6060+ --variable="root=${backtoblogroot}" \
4661 --variable="path=${post#./}" \
4747- --metadata-file="${post}/meta.json" \
4848- "${post}/content.djot" -o "${post}/index.html"
6262+ --metadata-file=<(printf %s "$meta") \
6363+ "${pandoc_args[@]}" || pandoc_error=$?
6464+ popd >/dev/null
6565+ [ "$pandoc_error" != 0 ] && echo "warning: pandoc exited with code $pandoc_error, skipping" >&2 && continue
6666+6767+ jq -r --arg path "${post}" "${template}" <<<"$meta" >> ./index.html
4968done
50695170sed -n "/${template_end}/,\$p" "${index_template}" >> ./index.html
-1
src/blog/2025-09-14-test/meta.json
···11{
22 "title": "me and my stupid chud blog ssg child",
33- "lang": "en",
43 "date": "2025-09-14",
54 "tags": ["test", "test2"]
65}
-1
src/blog/2025-09-16-mastodon-stats/meta.json
···11{
22 "title": "see how many times you've talked with someone on the fediverse",
33- "lang": "en",
43 "date": "2025-09-16",
54 "tags": ["software", "short"],
65 "keywords": ["mastodon", "fediverse", "statistics"]