aboutsummaryrefslogtreecommitdiff
path: root/v2/src/development/getconf.sh
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-04-04 08:33:41 -0300
committerEuAndreh <eu@euandre.org>2023-04-04 08:43:15 -0300
commit08588f9907299b1a927e281d5c65b46b7cefa427 (patch)
tree860f8550c2efee35df9bfa1ef56e338f8331c2d1 /v2/src/development/getconf.sh
parentdynamic.mk: Use serve(1) as is (diff)
downloadeuandre.org-08588f9907299b1a927e281d5c65b46b7cefa427.tar.gz
euandre.org-08588f9907299b1a927e281d5c65b46b7cefa427.tar.xz
Revamp v2/
Diffstat (limited to '')
-rwxr-xr-xv2/src/development/getconf.sh119
1 files changed, 119 insertions, 0 deletions
diff --git a/v2/src/development/getconf.sh b/v2/src/development/getconf.sh
new file mode 100755
index 0000000..dd623f7
--- /dev/null
+++ b/v2/src/development/getconf.sh
@@ -0,0 +1,119 @@
+#!/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'
+}
+
+{
+ cat src/lib/base-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|^ ||' | escape)"
+ printf '%s="%s"\n' "$KEY" "$VALUE"
+ done < "$FILENAME" | tee -a "$FILENAME".tmp
+ . "$FILENAME".tmp
+
+ cat src/lib/base."$lang".conf
+ . src/lib/base."$lang".conf
+
+ title="${title:-"$site_name"}"
+ url_part="$(printf '%s' "${FILENAME%.md}.html" | sed 's|^src/content/||')"
+
+ printf 'title="%s"\n' "$(printf '%s' "$title" | escape)"
+ printf 'title_html="%s"\n' "$(printf '%s' "$title" | htmlesc | escape)"
+ printf 'filename="%s"\n' "$FILENAME"
+ printf 'url_part="%s"\n' "$url_part"
+ printf 'url="%s"\n' "$(url-for "$url_part" | absolute)"
+ printf 'date_formatted="%s"\n' "$(LANG="$lang" date -d "$date" +"$date_fmt" | escape)"
+ printf 'mailto_uri="%s%s"\n' "$mailto_uri_prefix" "$(uri "$title")"
+ printf 'discussions_url="%s%s"\n' "$discussions_url_prefix" "$(uri "$title")"
+ printf 'sourcecode_url="%s%s"\n' "$sourcecode_url_prefix" "$FILENAME"
+
+ printf 'lang_url="%s"\n' "$(url-for "$lang"/)"
+
+ printf 'style_url="%s"\n' "$(url-for 'style.css')"
+ printf 'favicon_url="%s"\n' "$(url-for 'favicon.svg')"
+
+ rm -f "$FILENAME".tmp
+} | grep . | sed 's|^|export |'