diff options
-rw-r--r-- | v2/.envrc | 4 | ||||
-rw-r--r-- | v2/dynamic.mk | 4 | ||||
-rwxr-xr-x | v2/src/bin/absolute | 67 | ||||
-rwxr-xr-x | v2/src/bin/url-for | 77 | ||||
-rwxr-xr-x | v2/src/development/genhtml.sh | 31 |
5 files changed, 161 insertions, 22 deletions
diff --git a/v2/.envrc b/v2/.envrc new file mode 100644 index 0000000..1bdbb88 --- /dev/null +++ b/v2/.envrc @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu + +export PATH="$PWD/src/bin:$PATH" diff --git a/v2/dynamic.mk b/v2/dynamic.mk index ca0f245..09edfa7 100644 --- a/v2/dynamic.mk +++ b/v2/dynamic.mk @@ -40,8 +40,8 @@ ALL = \ all: $(ALL) - -$(html): src/development/genhtml.sh src/development/config.env +$(html) src/bin/absolute src/bin/url-for: src/development/config.env +$(html): src/development/genhtml.sh collections = pastebins diff --git a/v2/src/bin/absolute b/v2/src/bin/absolute new file mode 100755 index 0000000..ae25b43 --- /dev/null +++ b/v2/src/bin/absolute @@ -0,0 +1,67 @@ +#!/bin/sh +set -eu + + +usage() { + cat <<-'EOF' + Usage: + absolute < STDIN + absolute -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -h, --help show this message + + + Read URL from STDIN and adds the FQDN prefix. Meant to be used + in conjunction with `url-for`. + + + Examples: + + Get the URL for "static/style.css", and make it absolute: + + $ url-for 'static/style.css' | absolute + https://euandre.org/static/style.css + 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/config.env + +printf 'https://%s%s' "$FQDN" "$(cat)" diff --git a/v2/src/bin/url-for b/v2/src/bin/url-for new file mode 100755 index 0000000..025a546 --- /dev/null +++ b/v2/src/bin/url-for @@ -0,0 +1,77 @@ +#!/bin/sh +set -eu + + +usage() { + cat <<-'EOF' + Usage: + url-for FILE + url-for -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -h, --help show this message + + FILE the path for the URL to be constructed + + + Build an URL for the given FILE, without the FQDN part, adding + the required BASE_URL. + + + Examples: + + Get the URL for "static/style.css", when BASE_URL is empty: + + $ url-for 'static/style.css' + /static/style.css + + + Get the URL for "static/favicon.svg", when BASE_URL is "v2": + + $ url-for 'static/favicon.svg' + /v2/static/favicon.svg + 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)) + +FILE="${1:-}" +eval "$(assert-arg "$FILE" 'FILE')" + +. src/development/config.env + +printf '%s/%s' "$BASE_URL" "$FILE" diff --git a/v2/src/development/genhtml.sh b/v2/src/development/genhtml.sh index 953a80d..3f1bca6 100755 --- a/v2/src/development/genhtml.sh +++ b/v2/src/development/genhtml.sh @@ -12,7 +12,6 @@ set -eu # - sitemap? How does it even work? # - dark mode # - generate security.txt dynamically -# - make url_for a standalone executable # - config.env should depend on dynamic.mk? @@ -91,14 +90,6 @@ eval "$(assert-arg "$FILENAME" 'FILENAME')" # Utility functions # -url_for() { - printf '%s/%s' "$BASE_URL" "$1" -} - -absolute() { - printf 'https://%s%s' "$FQDN" "$(cat)" -} - translate() { printf '%s' "$1" } @@ -166,7 +157,7 @@ extract_plaintext_snippets() { printf '%s\n' "$line" if [ "$line" = '</code></pre>' ]; then - printf '<p class="plaintext-link"><a href="%s.%s.txt">plaintext</a></p>\n' "$(url_for "$URL")" "$BLOCK_NUMBER" + printf '<p class="plaintext-link"><a href="%s.%s.txt">plaintext</a></p>\n' "$(url-for "$URL")" "$BLOCK_NUMBER" BLOCK_NUMBER=$((BLOCK_NUMBER + 1)) fi done < "$F" @@ -218,7 +209,7 @@ add_headings_anchors() { "$SLUG" \ "$HEADING" \ "$SLUG" \ - "$(url_for 'static/link.svg')" \ + "$(url-for 'static/link.svg')" \ "$LVL" done ) @@ -275,8 +266,8 @@ cat <<-EOF <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="$(url-for 'static/styles.css')" /> + <link rel="icon" type="image/svg+xml" href="$(url-for 'static/favicon.svg')" /> <title>$TITLE</title> @@ -285,15 +276,15 @@ cat <<-EOF <meta property="og:locale" content="$LANGUAGE" /> <meta property="og:title" content="$TITLE" /> - <link rel="canonical" href="$(url_for "$URL" | absolute)" /> - <meta property="og:url" content="$(url_for "$URL" | absolute)" /> + <link rel="canonical" href="$(url-for "$URL" | absolute)" /> + <meta property="og:url" content="$(url-for "$URL" | absolute)" /> </head> <body> <header> <nav> <ul> - <a href="$(url_for "$LANGUAGE/")">$(_ 'EuAndreh')</a> - <a href="$(url_for "$(_ 'about.html')")">$(_ 'About')</a> + <a href="$(url-for "$LANGUAGE/")">$(_ 'EuAndreh')</a> + <a href="$(url-for "$(_ 'about.html')")">$(_ 'About')</a> </ul> </nav> <hr /> @@ -315,12 +306,12 @@ cat <<-EOF <hr /> <ul> <li> - <img class="svg-icon" src="$(url_for 'static/envelope.svg')" alt="$(_ 'a envelope icon representing an email address')" /> + <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> </li> <li> - <img class="svg-icon" src="$(url_for 'static/lock.svg')" alt="$(_ 'a lock icon representing a GPG public key')" /> - <a href="$(url_for 'static/public.asc.txt')">81F90EC3CD356060</a> + <img class="svg-icon" src="$(url-for 'static/lock.svg')" alt="$(_ 'a lock icon representing a GPG public key')" /> + <a href="$(url-for 'static/public.asc.txt')">81F90EC3CD356060</a> </li> </ul> <p> |