diff options
author | EuAndreh <eu@euandre.org> | 2023-04-04 08:33:41 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2023-04-04 08:43:15 -0300 |
commit | 08588f9907299b1a927e281d5c65b46b7cefa427 (patch) | |
tree | 860f8550c2efee35df9bfa1ef56e338f8331c2d1 /v2/src/development | |
parent | dynamic.mk: Use serve(1) as is (diff) | |
download | euandre.org-08588f9907299b1a927e281d5c65b46b7cefa427.tar.gz euandre.org-08588f9907299b1a927e281d5c65b46b7cefa427.tar.xz |
Revamp v2/
Diffstat (limited to 'v2/src/development')
-rw-r--r-- | v2/src/development/config.env.in | 6 | ||||
-rwxr-xr-x | v2/src/development/dynmake.sh | 79 | ||||
-rwxr-xr-x | v2/src/development/genhtml.sh | 68 | ||||
-rwxr-xr-x | v2/src/development/getconf.sh | 119 | ||||
-rw-r--r-- | v2/src/development/lib.sh | 33 | ||||
-rwxr-xr-x | v2/src/development/security-txt.sh.in | 82 |
6 files changed, 273 insertions, 114 deletions
diff --git a/v2/src/development/config.env.in b/v2/src/development/config.env.in deleted file mode 100644 index ca2afe7..0000000 --- a/v2/src/development/config.env.in +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -SITE_NAME="EuAndreh's website" -FQDN='@FQDN@' -BASE_URL='@BASE_URL@' -DATE_FMT='+%B %-d, %Y' diff --git a/v2/src/development/dynmake.sh b/v2/src/development/dynmake.sh deleted file mode 100755 index 126c211..0000000 --- a/v2/src/development/dynmake.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/sh -set -eu - - -usage() { - cat <<-'EOF' - Usage: - dynmake.sh - dynmake.sh -h - EOF -} - -help() { - cat <<-'EOF' - - Options: - -h, --help show this message - - - Generate make(1) code for later evaluation by make(1). What - this scripts does is fill the gap where make(1) can't handle - globs and dynamic dependencies, and uses some ad-hoc scripts - to generate those. - 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)) - - - -varlist() { - sed -e 's/^/ /' \ - -e 's/$/ \\/' -} - - -# -# Pastebins -# - -pastebins() { - find src/content/pastebins/ -name '*.md' -} - -printf 'pastebins.md = \\\n' -pastebins | varlist -printf '\n' - -pastebins | sed 's/^\(.*\)\.md$/\1.html: \1.entry-env/' -pastebins | sed 's/^\(.*\)\.md$/\1.html: \1.entry-content/' -pastebins | sed 's/^\(.*\)\.md$/\1.entry-content: \1.entry-env/' diff --git a/v2/src/development/genhtml.sh b/v2/src/development/genhtml.sh index a1e8afb..cb8fd73 100755 --- a/v2/src/development/genhtml.sh +++ b/v2/src/development/genhtml.sh @@ -1,21 +1,6 @@ #!/bin/sh set -eu -# FIXMEs: -# - feeds -# - link to next and/or previous in <head> -# - translation support -# - validate input variables: regex for date (same as _plugins/linter.rb) -# - `date -d` isn't POSIX -# - parse commonmark and use a custom HTML emitter over <pre><code> regex -# - handle mixture of personal scripts -# - sitemap? How does it even work? -# - dark mode -# - generate security.txt dynamically -# - config.env should depend on dynamic.mk? - - - usage() { cat <<-'EOF' Usage: @@ -81,12 +66,13 @@ while getopts 'h' flag; do done shift $((OPTIND - 1)) +. src/development/lib.sh FILENAME="${1:-}" -eval "$(assert-arg "$FILENAME" 'FILENAME')" +eval "$(assert_arg "$FILENAME" 'FILENAME')" -. "${FILENAME%.md}.entry-env" +. "${FILENAME%.md}.conf" # # Utility functions @@ -216,28 +202,28 @@ emit_body() { cat <<-EOF <!DOCTYPE html> - <html lang="$LANGUAGE"> + <html lang="$lang"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> - <link rel="stylesheet" type="text/css" href="$(url-for 'static/styles.css')" /> - <link rel="icon" type="image/svg+xml" href="$(url-for 'static/favicon.svg')" /> + <link rel="stylesheet" type="text/css" href="$style_url" /> + <link rel="icon" type="image/svg+xml" href="$favicon_url" /> - <title>$TITLE</title> + <title>$$title_html</title> <meta name="author" content="EuAndreh" /> - <meta property="og:site_name" content="$SITE_NAME" /> - <meta property="og:locale" content="$LANGUAGE" /> - <meta property="og:title" content="$TITLE" /> + <meta property="og:site_name" content="$site_name" /> + <meta property="og:locale" content="$lang" /> + <meta property="og:title" content="$title_html" /> - <link rel="canonical" href="$(url-for "$URL" | absolute)" /> - <meta property="og:url" content="$(url-for "$URL" | absolute)" /> + <link rel="canonical" href="$url" /> + <meta property="og:url" content="$url" /> </head> <body> <header> <nav> <ul> - <a href="$(url-for "$LANGUAGE/")">EuAndreh</a> + <a href="$(url-for "$lang/")">EuAndreh</a> <a href="$(url-for 'about.html')">About</a> </ul> </nav> @@ -245,8 +231,19 @@ cat <<-EOF </header> <main> <article> - $(emit_body) + \$(emit_body) <hr /> +EOF +exit + + +.md.rehtml: + F="$<"; . "$${F%.md}.conf"; envsubst < src/lib/reamble."$$lang".html > $@ + +.md.osthtml: + F="$<"; . "$${F%.md}.conf"; envsubst < src/lib/ostamble."$$lang".html > $@ + + <p class="post-footer"> <a href="mailto:~euandreh/public-inbox@lists.sr.ht?Subject=Re%3A%20$URI_TITLE">Comment</a> and see @@ -261,7 +258,7 @@ cat <<-EOF <ul> <li> <img class="svg-icon" src="$(url-for 'static/envelope.svg')" alt="a envelope icon representing an email address" /> - <a href="mailto:eu@euandre.org">eu@euandre.org</a> + <a href="mailto:$email">$email</a> </li> <li> <img class="svg-icon" src="$(url-for 'static/lock.svg')" alt="a lock icon representing a GPG public key" /> @@ -275,3 +272,16 @@ cat <<-EOF </body> </html> EOF + +# FIXMEs: +# - feeds +# - link to next and/or previous in <head> +# - translation support +# - validate input variables: regex for date (same as _plugins/linter.rb) +# - `date -d` isn't POSIX +# - parse commonmark and use a custom HTML emitter over <pre><code> regex +# - handle mixture of personal scripts +# - sitemap? How does it even work? +# - dark mode +# - generate security.txt dynamically +# - config.env should depend on dynamic.mk? 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 |' diff --git a/v2/src/development/lib.sh b/v2/src/development/lib.sh new file mode 100644 index 0000000..9d183f9 --- /dev/null +++ b/v2/src/development/lib.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +assert_arg() { + if [ -z "$1" ]; then + printf 'Missing %s.\n\n' "$2" >&2 + cat <<-'EOF' + usage >&2 + exit 2 + EOF + fi +} + +uuid() { + od -xN20 /dev/urandom | + head -n1 | + awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}' +} + +tmpname() { + echo "${TMPDIR:-/tmp}/uuid-tmpname with spaces.$(uuid)" +} + +mkstemp() { + name="$(tmpname)" + touch "$name" + echo "$name" +} + +mkdtemp() { + name="$(tmpname)" + mkdir "$name" + echo "$name" +} diff --git a/v2/src/development/security-txt.sh.in b/v2/src/development/security-txt.sh.in new file mode 100755 index 0000000..8f6613f --- /dev/null +++ b/v2/src/development/security-txt.sh.in @@ -0,0 +1,82 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + src/development/security-txt.sh + src/development/security-txt.sh -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + + Generate the RFC 9116 "security.txt" file from data in the + repository. + + + Examples: + + Just run it: + + $ sh src/development/security-txt.sh > .well-known/security.txt + 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)) + + + +EXPIRES="$( + LANG=C.UTF-8 gpg --list-key eu@euandre.org | + awk '/^pub/ { print substr($(NF), 1, 10) }' +)T00:00:00z" + +LANGS="en$( + echo po/??.po | + sed 's|\.po$||' | + sed 's|^po/|, |' | + paste -sd, +)" + + +cat <<-EOF + Contact: mailto:@EMAIL@ + Encryption: https://@DOMAIN@/public.asc.txt + Expires: $EXPIRES + Preferred-Languages: $LANGS +EOF |