aboutsummaryrefslogtreecommitdiff
path: root/v2/src/bin/conf
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-04-08 13:22:48 -0300
committerEuAndreh <eu@euandre.org>2023-04-08 13:24:25 -0300
commitee71be14a05d0d7da38352f8ff5c19798f96d4eb (patch)
tree219353fc97fa32bfe5fcadbfcdd024f768d2b2d2 /v2/src/bin/conf
parentv2: src/bin/html: Turn extract_plaintext_snippets() into a () function (diff)
downloadeuandre.org-ee71be14a05d0d7da38352f8ff5c19798f96d4eb.tar.gz
euandre.org-ee71be14a05d0d7da38352f8ff5c19798f96d4eb.tar.xz
v2: Generate collections index.html pages and their "by-category" equivalents
Diffstat (limited to '')
-rwxr-xr-xv2/src/bin/conf69
1 files changed, 43 insertions, 26 deletions
diff --git a/v2/src/bin/conf b/v2/src/bin/conf
index 5717039..62ef97a 100755
--- a/v2/src/bin/conf
+++ b/v2/src/bin/conf
@@ -5,7 +5,7 @@ set -eu
usage() {
cat <<-'EOF'
Usage:
- conf FILENAME
+ conf [FILENAME]
conf -h
EOF
}
@@ -21,7 +21,8 @@ help() {
Separate the content from the "frontmatter", and emit the
- selected one, given the FILENAME.
+ selected one, given the FILENAME. If FILENAME is not given,
+ generate the global config.
Examples:
@@ -65,11 +66,36 @@ shift $((OPTIND - 1))
. src/lib.sh
+
FILENAME="${1:-}"
-eval "$(assert_arg "$FILENAME" 'FILENAME')"
+if [ -z "$FILENAME" ]; then
+ printf 'export style_url="%s"\n' "$(url-for 'style.css')"
+ printf 'export pubkey_url="%s"\n' "$(url-for 'public.asc.txt')"
+ printf 'export pubkey_id="%s"\n' "$(
+ LANG=C.UTF-8 gpg --list-key "$EMAIL" |
+ awk 'NR==2 { print substr($1, length($1) - 15) }' |
+ shesc
+ )"
+
+ for f in "$CONTENT_PREFIX"/img/*.svg; do
+ name="$(basename "$f" .svg | sed 's|-|_|g')"
+ printf 'export icon_%s_url="%s"\n' "$name" "$(url-for "img/$(basename "$f")")"
+ done
+ for l in $(langs); do
+ for f in "$CONTENT_PREFIX"/img/*.svg; do
+ name="$(basename "$f" .svg | sed 's|-|_|g')"
+ printf 'export icon_%s_alt="%s"\n' "$name" "$(shesc < "$CONTENT_PREFIX/img/alt/$(basename "$f" .svg).$l.txt" )"
+ done > src/lib/generated."$l".conf
+ done
+ exit
+fi
+
+lang="$(lang-for "$FILENAME")"
+export lang
-tee "$FILENAME".tmp < src/lib/base.conf
+cat src/lib/base.conf src/lib/generated.conf src/lib/generated."$lang".conf |
+ tee "$FILENAME".tmp
DELIMITER=0
while read -r line; do
if [ "$line" = '---' ]; then
@@ -92,14 +118,17 @@ done < "$FILENAME" | tee -a "$FILENAME".tmp
rm -f "$FILENAME".tmp
+collection="$(collection-for "$FILENAME" ||:)"
+if [ -n "$collection" ]; then
+ export collection
+ printf 'export collection="%s"\n' "$collection"
+fi
+
if [ -z "${layout:-}" ]; then
- if [ "$(dirname "$(dirname "$FILENAME")")" = "$CONTENT_PREFIX" ]; then
+ if [ -z "$collection" ]; then
layout=page
else
layout=post
- collection="$(basename "$(dirname "$FILENAME")")"
- export collection
- printf 'export collection="%s"\n' "$collection"
custom_layout="$(echo "$LAYOUTS" | grep . |
awk -v coll="$collection" '$1 == coll { print $2 }'
@@ -131,10 +160,10 @@ if [ -n "${date:-}" ]; then
formatted_date="$(LANG="$lang" date -ud "${date:?}" +"${date_fmt:?}")"
export formatted_date
+ printf 'export formatted_date_html="%s"\n' "$(htmlesc "$formatted_date" | shesc)"
printf 'export date_html="%s"\n' "$(envsubst < src/lib/date."$lang".html | shesc)"
- echo "${FILENAME%.md}.xmlentry" > "$(dirname "$FILENAME")/$date_iso.sortdata"
- touch "${FILENAME%.md}.sortref"
+ echo "$FILENAME" > "$(dirname "$FILENAME")/$date_iso.sortdata"
fi
if [ -n "${update:-}" ]; then
@@ -149,31 +178,19 @@ if [ -n "${update:-}" ]; then
fi
-url_part="$(printf '%s' "${FILENAME%.md}.html" | sed "s|^$CONTENT_PREFIX||")"
+url_part="$(printf '%s' "${FILENAME%.md}.html" | sed "s|^$CONTENT_PREFIX/||")"
+url="$(url-for "$url_part")"
title_uri="$(uri "$title")"
printf 'export title_html="%s"\n' "$(printf '%s' "$title" | htmlesc | shesc)"
printf 'export filename="%s"\n' "$FILENAME"
printf 'export url_part="%s"\n' "$url_part"
-printf 'export url="%s"\n' "$(url-for "$url_part" | absolute)"
+printf 'export url="%s"\n' "$url"
+printf 'export url_absolute="%s"\n' "$(absolute "$url")"
printf 'export mailto_uri="%s%s"\n' "${mailto_uri_prefix:?}" "$title_uri"
printf 'export discussions_url="%s%s"\n' "${discussions_url_prefix:?}" "$title_uri"
printf 'export sourcecode_url="%s%s"\n' "${sourcecode_url_prefix:?}" "$FILENAME"
-printf 'export style_url="%s"\n' "$(url-for 'style.css')"
-printf 'export favicon_url="%s"\n' "$(url-for 'favicon.svg')"
-printf 'export pubkey_url="%s"\n' "$(url-for 'public.asc.txt')"
-
-for f in "$CONTENT_PREFIX"/img/*.svg; do
- name="$(basename "$f" .svg | sed 's|-|_|g')"
- printf 'export icon_%s_url="%s"\n' "$name" "$(url-for "img/$(basename "$f")")"
-done
-
-# FIXME: special treatment of root
-printf 'export homepage_url="%s"\n' "$(url-for '/')"
-
-printf 'export about_url="%s"\n' "$(url-for "${about_url_name:?}")"
-
if [ "${layout:-}" = 'post' ]; then
export mailto_uri="$mailto_uri_prefix$title_uri"