#!/bin/sh set -eu usage() { cat <<-'EOF' Usage: conf [FILENAME] conf -h EOF } help() { cat <<-'EOF' Options: -h, --help show this message FILENAME the name of the input file, also to be used as URL. Separate the content from the "frontmatter", and emit the selected one, given the FILENAME. If FILENAME is not given, generate the global config. Examples: Get the "frontmatter" of src/f.conf: $ conf src/f.md > src/f.conf 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:-}" 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 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 DELIMITER=$((DELIMITER + 1)) continue fi if [ "$DELIMITER" = 2 ]; then break fi if [ -z "$line" ]; then continue fi KEY="$( printf '%s' "$line" | cut -d: -f1)" VALUE="$(printf '%s' "$line" | cut -d: -f2- | sed 's|^ ||' | shesc)" printf 'export %s="%s"\n' "$KEY" "$VALUE" done < "$FILENAME" | tee -a "$FILENAME".tmp # shellcheck source=/dev/null . "$FILENAME".tmp rm -f "$FILENAME".tmp lang="$(lang-for "$FILENAME")" export lang printf 'export lang="%s"\n' "$lang" cat src/lib/base."${lang:?}".conf # shellcheck source=/dev/null . src/lib/base."$lang".conf if [ -z "${title:-}" ]; then title="${site_name:?}" printf 'export title="%s"\n' "$(printf '%s' "$title" | shesc)" fi collection="$(collection-for "$FILENAME" ||:)" if [ -n "$collection" ]; then export collection printf 'export collection="%s"\n' "$collection" coll_path="$(coll2path "$lang" "$collection")" feed_title="$(eval "echo \"\$feed_${collection}_title\"" | htmlesc)" collection_head_html="$(printf ' ' \ "$(url-for "$lang/$coll_path")" \ "$(htmlesc "$feed_title")" )" printf 'export collection_head_html="%s"\n' "$(shesc "$collection_head_html")" fi if [ -z "${layout:-}" ]; then if [ -z "$collection" ]; then layout=page else layout=post custom_layout="$(echo "$LAYOUTS" | grep . | awk -v coll="$collection" '$1 == coll { print $2 }' )" if [ -n "$custom_layout" ]; then layout="$custom_layout" fi fi export layout printf 'export layout="%s"\n' "$layout" fi if [ -r "$FILENAME".i18n ]; then translations_head="$(awk -F: -v lang="$lang" '$1 != lang{ printf " \n", $3, $1 }' "$FILENAME".i18n)" translations_body="$(cat <<-EOF