diff options
author | EuAndreh <eu@euandre.org> | 2023-04-09 18:59:09 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2023-04-09 19:05:39 -0300 |
commit | 19a8b995c59cce5315e1d121054f9c27aad5c960 (patch) | |
tree | f2c2d83751245004beed21b31d973c1d412cd026 /v2/src/bin | |
parent | v2: CSS dark mode, including SVGs (diff) | |
download | euandre.org-19a8b995c59cce5315e1d121054f9c27aad5c960.tar.gz euandre.org-19a8b995c59cce5315e1d121054f9c27aad5c960.tar.xz |
v2: Support translated alternates in <nav>
Diffstat (limited to 'v2/src/bin')
-rwxr-xr-x | v2/src/bin/conf | 18 | ||||
-rwxr-xr-x | v2/src/bin/i18n | 87 | ||||
-rwxr-xr-x | v2/src/bin/index | 15 | ||||
-rwxr-xr-x | v2/src/bin/url-for | 39 |
4 files changed, 140 insertions, 19 deletions
diff --git a/v2/src/bin/conf b/v2/src/bin/conf index 92ecc68..e4dba61 100755 --- a/v2/src/bin/conf +++ b/v2/src/bin/conf @@ -154,6 +154,20 @@ if [ -z "${title:-}" ]; then printf 'export title="%s"\n' "$(printf '%s' "$title" | shesc)" fi +if [ -r "$FILENAME".i18n ]; then + translations="$(cat <<-EOF + <ul class="translation-list"> + $(awk -F: '{ + "url-for " $2 | getline url + printf " <li><a href=\"%s\">%s</a></li>\n", + url, $1 + }' "$FILENAME".i18n) + </ul> + EOF + )" + printf 'export translations_html="%s"\n' "$(shesc "$translations")" +fi + if [ -n "${date:-}" ]; then date_iso="$(date -ud "${date:?}" -Is)" printf 'export date_iso="%s"\n' "$date_iso" @@ -178,8 +192,8 @@ if [ -n "${update:-}" ]; then fi -url_part="$(printf '%s' "${FILENAME%.*}.html" | sed "s|^$CONTENT_PREFIX/||")" -url="$(url-for "$url_part")" +url="$(url-for "$FILENAME")" +url_part="$(printf '%s' "$url" | sed 's|^/||')" title_uri="$(uri "$title")" printf 'export title_html="%s"\n' "$(printf '%s' "$title" | htmlesc | shesc)" diff --git a/v2/src/bin/i18n b/v2/src/bin/i18n new file mode 100755 index 0000000..76e07e7 --- /dev/null +++ b/v2/src/bin/i18n @@ -0,0 +1,87 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + i18n + i18n -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + + Look at the mappings file provided via STDIN and notify all of + the files of all of their translations, so that they can include + it in their header. + + + Examples: + + Generate it from "po/i18n.mappings": + + $ i18n < po/i18n.mappings + 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)) + + + +awk ' +{ + from = $3 + idx[from][0] = "en:" from + for (i = 4; i <= NF; i++) { + to = $i + idx[from][length(idx[from])] = to + } +} + +END { + for (k1 in idx) { + for (k2 in idx[k1]) { + split(idx[k1][k2], a, /:/) + file = a[2] ".i18n" + for (k3 in idx[k1]) { + print idx[k1][k3] > file + } + } + } +} +' diff --git a/v2/src/bin/index b/v2/src/bin/index index 46e0c88..553cc27 100755 --- a/v2/src/bin/index +++ b/v2/src/bin/index @@ -75,8 +75,7 @@ l="$(lang-for "$FILENAME")" # shellcheck source=/dev/null . src/lib/base."$l".conf -url_part="$(printf '%s' "${FILENAME#"$CONTENT_PREFIX"/}" | sed "s|\.md$|.html|")" -url_absolute="$(url-for "$url_part" | absolute)" +url_absolute="$(url-for "$FILENAME" | absolute)" collection="$(collection-for "$FILENAME")" feed_url="$(url-for "${DIR#"$CONTENT_PREFIX"/}"/feed.xml)" by_category_url="$(url-for "${DIR#"$CONTENT_PREFIX"/}/${by_category_url_name:?}")" @@ -86,6 +85,18 @@ index_category_title_html="$(eval "echo \"\$index_category_${collection}_title\" export url_absolute feed_url by_category_url title_html index_recent_title_html \ index_category_title_html +translations_html="$(cat <<-EOF + <ul class="translation-list"> + $(langs | awk -v coll="$collection" '{ + "coll2path " $0 " " coll | getline coll_path + "url-for " $0 "/" coll_path | getline url + printf " <li><a href=\"%s\">%s</a></li>\n", url, $0 + }') + </ul> +EOF +)" +export translations_html + mkdir -p "$DIR" diff --git a/v2/src/bin/url-for b/v2/src/bin/url-for index a1b4d1a..e0b1c9d 100755 --- a/v2/src/bin/url-for +++ b/v2/src/bin/url-for @@ -4,7 +4,7 @@ set -eu usage() { cat <<-'EOF' Usage: - url-for FILE + url-for [CONTENT...] url-for -h EOF } @@ -15,11 +15,11 @@ help() { Options: -h, --help show this message - FILE the path for the URL to be constructed + CONTENT literal strings to be transformed into URLs - Build an URL for the given FILE, without the $domain part, adding - the required $base_url. + Build an URL without the $domain part, adding the required + $base_url. If CONTENT is not given, get data from STDIN. Examples: @@ -32,7 +32,7 @@ help() { Get the URL for "static/favicon.svg", when $base_url is empty: - $ url-for 'img/link.svg' + $ echo 'img/link.svg' | url-for /img/link.svg EOF } @@ -68,17 +68,26 @@ while getopts 'h' flag; do done shift $((OPTIND - 1)) -. src/lib.sh - -FILE="${1:-}" -eval "$(assert_arg "$FILE" 'FILE')" - - -if [ "$FILE" = '/' ]; then - FILE='' -fi . src/lib/base.conf -printf '%s%s' "${base_url:-/}" "$FILE" +url() { + sed \ + -e "s|^$CONTENT_PREFIX/||" \ + -e 's|\.md|.html|' \ + -e 's|\.page|.html|' \ + -e 's|^/||' | + printf '%s%s\n' "${base_url:-/}" "$(cat -)" +} + +if [ $# = 0 ]; then + url +else + for f in "$@"; do + if [ "$f" = '/' ]; then + f='' + fi + printf '%s\n' "$f" | url + done +fi |