From f284c680fb1a72bc0d237c161eabffeda672d279 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 4 Apr 2023 17:41:14 -0300 Subject: v2: git mv src/development/getconf.sh src/development/genconf.sh --- v2/dynamic.mk | 2 +- v2/src/development/genconf.sh | 150 ++++++++++++++++++++++++++++++++++++++++++ v2/src/development/getconf.sh | 150 ------------------------------------------ 3 files changed, 151 insertions(+), 151 deletions(-) create mode 100755 v2/src/development/genconf.sh delete mode 100755 v2/src/development/getconf.sh (limited to 'v2') diff --git a/v2/dynamic.mk b/v2/dynamic.mk index 918c270..b31e269 100644 --- a/v2/dynamic.mk +++ b/v2/dynamic.mk @@ -20,7 +20,7 @@ include generated.mk if [ -x $< ]; then chmod +x $@; fi .md.conf: - sh src/development/getconf.sh $< > $@ + sh src/development/genconf.sh $< > $@ .md.content: awk 'sep >= 2; /^---$$/ {sep++}' < $< > $@ diff --git a/v2/src/development/genconf.sh b/v2/src/development/genconf.sh new file mode 100755 index 0000000..f9dfc14 --- /dev/null +++ b/v2/src/development/genconf.sh @@ -0,0 +1,150 @@ +#!/bin/sh +set -eu + + +usage() { + cat <<-'EOF' + Usage: + src/development/genconf.sh FILENAME + src/development/genconf.sh -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. + + + Examples: + + Get the "frontmatter" of src/f.conf: + + $ src/development/genconf.sh 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/development/lib.sh + +FILENAME="${1:-}" +eval "$(assert_arg "$FILENAME" 'FILENAME')" + + +escape() { + sed 's|\([`"$]\)|\\\1|g' +} + +tee "$FILENAME".tmp < src/lib/base-conf +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|^ ||' | escape)" + printf 'export %s="%s"\n' "$KEY" "$VALUE" +done < "$FILENAME" | tee -a "$FILENAME".tmp +# shellcheck source=/dev/null +. "$FILENAME".tmp +rm -f "$FILENAME".tmp + +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" | escape)" +fi + +if [ -n "${date:-}" ]; then + formatted_date="$(LANG="$lang" date -d "${date:?}" +"${date_fmt:?}")" + export formatted_date + printf 'export date_html="%s"\n' "$(envsubst < src/lib/date."$lang".html | escape)" +fi + +if [ -n "${update:-}" ]; then + formatted_update="$(LANG="$lang" date -d "${update:?}" +"${date_fmt:?}")" + export formatted_update + printf 'export update_html="%s"\n' "$(envsubst < src/lib/update."$lang".html | escape)" +fi + + +url_part="$(printf '%s' "${FILENAME%.md}.html" | sed 's|^src/content/||')" +title_uri="$(uri "$title")" + +printf 'export title_html="%s"\n' "$(printf '%s' "$title" | htmlesc | escape)" +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 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 -g 'style.css')" +printf 'export favicon_url="%s"\n' "$(url-for -g 'favicon.svg')" +printf 'export pubkey_url="%s"\n' "$(url-for -g 'public.asc.txt')" + +for f in src/content/img/*.svg; do + name="$(basename "$f" .svg | sed 's|-|_|g')" + printf 'export icon_%s_url="%s"\n' "$name" "$(url-for -g "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" + export discussions_url="$discussions_url_prefix$title_uri" + export sourcecode_url="$sourcecode_url_prefix$FILENAME" + printf 'export comment_html="%s"\n' "$(envsubst < src/lib/comment."$lang".html | escape)" +fi diff --git a/v2/src/development/getconf.sh b/v2/src/development/getconf.sh deleted file mode 100755 index 3f7ccd2..0000000 --- a/v2/src/development/getconf.sh +++ /dev/null @@ -1,150 +0,0 @@ -#!/bin/sh -set -eu - - -usage() { - cat <<-'EOF' - Usage: - src/development/getconf.sh FILENAME - src/development/getconf.sh -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. - - - Examples: - - Get the "frontmatter" of src/f.conf: - - $ src/development/getconf.sh 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/development/lib.sh - -FILENAME="${1:-}" -eval "$(assert_arg "$FILENAME" 'FILENAME')" - - -escape() { - sed 's|\([`"$]\)|\\\1|g' -} - -tee "$FILENAME".tmp < src/lib/base-conf -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|^ ||' | escape)" - printf 'export %s="%s"\n' "$KEY" "$VALUE" -done < "$FILENAME" | tee -a "$FILENAME".tmp -# shellcheck source=/dev/null -. "$FILENAME".tmp -rm -f "$FILENAME".tmp - -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" | escape)" -fi - -if [ -n "${date:-}" ]; then - formatted_date="$(LANG="$lang" date -d "${date:?}" +"${date_fmt:?}")" - export formatted_date - printf 'export date_html="%s"\n' "$(envsubst < src/lib/date."$lang".html | escape)" -fi - -if [ -n "${update:-}" ]; then - formatted_update="$(LANG="$lang" date -d "${update:?}" +"${date_fmt:?}")" - export formatted_update - printf 'export update_html="%s"\n' "$(envsubst < src/lib/update."$lang".html | escape)" -fi - - -url_part="$(printf '%s' "${FILENAME%.md}.html" | sed 's|^src/content/||')" -title_uri="$(uri "$title")" - -printf 'export title_html="%s"\n' "$(printf '%s' "$title" | htmlesc | escape)" -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 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 -g 'style.css')" -printf 'export favicon_url="%s"\n' "$(url-for -g 'favicon.svg')" -printf 'export pubkey_url="%s"\n' "$(url-for -g 'public.asc.txt')" - -for f in src/content/img/*.svg; do - name="$(basename "$f" .svg | sed 's|-|_|g')" - printf 'export icon_%s_url="%s"\n' "$name" "$(url-for -g "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" - export discussions_url="$discussions_url_prefix$title_uri" - export sourcecode_url="$sourcecode_url_prefix$FILENAME" - printf 'export comment_html="%s"\n' "$(envsubst < src/lib/comment."$lang".html | escape)" -fi -- cgit v1.2.3