aboutsummaryrefslogtreecommitdiff
path: root/v2/src/bin/index
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/index
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 'v2/src/bin/index')
-rwxr-xr-xv2/src/bin/index128
1 files changed, 128 insertions, 0 deletions
diff --git a/v2/src/bin/index b/v2/src/bin/index
new file mode 100755
index 0000000..36750b3
--- /dev/null
+++ b/v2/src/bin/index
@@ -0,0 +1,128 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ collection FILENAME
+ collection -h
+ EOF
+}
+
+help() {
+ cat <<-'EOF'
+ Options:
+ -h, --help show this message
+
+ FILENAME the target collection HTML page to be generated
+
+
+ Generate FILENAME as a collection index. The collection type
+ and language are inferred by the name of FILENAME.
+
+
+ Examples:
+
+ Generate an index.html entry for english pastebins:
+
+ $ collection src/en/pastebins/index.html
+ EOF
+}
+
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+. src/lib.sh
+
+FILENAME="${1:-}"
+eval "$(assert_arg "$FILENAME" 'FILENAME')"
+DIR="$(dirname "$FILENAME")"
+
+
+l="$(lang-for "$FILENAME")"
+. src/lib/base.conf
+. src/lib/generated.conf
+# shellcheck source=/dev/null
+. src/lib/generated."$l".conf
+# shellcheck source=/dev/null
+. src/lib/base."$l".conf
+
+url_part="$(printf '%s' "${FILENAME#"$CONTENT_PREFIX"/}" | sed "s|\.md$|.html|")"
+url_absolute="$(url-for "$url_part" | absolute)"
+collection="$(collection-for "$FILENAME")"
+feed_url="$(url-for "${DIR#"$CONTENT_PREFIX"/}"/feed.xml)"
+by_category_url="$(url-for "${DIR#"$CONTENT_PREFIX"/}/${by_category_url_part:?}")"
+title_html="$(eval "echo \"\$index_${collection}_title\"" | htmlesc)"
+index_recent_title_html="$(eval "echo \"\$index_recent_${collection}_title\"" | htmlesc)"
+index_category_title_html="$(eval "echo \"\$index_category_${collection}_title\"" | htmlesc)"
+export url_absolute feed_url by_category_url title_html index_recent_title_html \
+ index_category_title_html
+
+
+
+mkdir -p "$DIR"
+{
+ cat src/lib/preamble.html src/lib/index-preamble.html | envsubst
+ find "$DIR"/*.sortdata 2>/dev/null |
+ sort -nr |
+ xargs cat |
+ sed 's|\.md$|.indexentry|' |
+ xargs cat
+ cat src/lib/index-postamble.html src/lib/postamble.html | envsubst
+} > "$FILENAME"
+
+
+CATEGORY_FILENAME="$CONTENT_PREFIX$by_category_url"
+echo "$CATEGORY_FILENAME" > "${FILENAME%.html}.extrahtml"
+
+url_absolute="$(absolute "$by_category_url")"
+title_html="$(eval "echo \"\$index_category_${collection}_title\"" | htmlesc)"
+export url_absolute title_html
+
+
+DIR="$(dirname "$CATEGORY_FILENAME")"
+mkdir -p "$DIR"
+{
+ envsubst < src/lib/preamble.html
+ while read -r category; do
+ feed_url="$(url-for "${DIR#"$CONTENT_PREFIX"/}/feed.$category.xml")"
+ index_recent_title_html="$category"
+ export category feed_url index_recent_title_html
+
+ envsubst < src/lib/category-header.html
+ echo ' <ul>'
+ < "$DIR/$category.category" \
+ sed 's|\.md$|.categoryentry|' |
+ xargs cat
+ echo ' </ul>'
+ done < "$DIR"/index.categories
+ envsubst < src/lib/postamble.html
+} > "$CATEGORY_FILENAME"