#!/bin/sh set -eu usage() { cat <<-'EOF' Usage: index FILENAME index -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: $ index src/en/pastebin/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_absolute="$(url-for "$FILENAME" | 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_name:?}")" 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 feed_title="$(eval "echo \"\$feed_${collection}_title\"")" collection_head_html="$(printf ' ' \ "$feed_url" \ "$(htmlesc "$feed_title")")" translations_head_html="$(langs | awk -v lang="${lang:?}" -v coll="$collection" '$0 != lang { "coll2path " $0 " " coll | getline coll_path "url-for " $0 "/" coll_path | getline url printf " \n", url, $0 }' )" translations_body_html="$(cat <<-EOF