From f28aae306abf524dbdbbec7e4cedcd2222ba80e1 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 4 Apr 2023 14:21:07 -0300 Subject: v2: WIP genhtml via envsubst --- v2/po/euandre.org.pot | 51 ++++-------------------- v2/po/po4a.cfg | 2 - v2/po/pt.po | 48 ++++------------------ v2/src/bin/url-for | 39 ++++++++++++------ v2/src/development/genhtml.sh | 92 +------------------------------------------ v2/src/development/getconf.sh | 21 +++++++--- v2/src/lib/base-conf.in | 4 +- v2/src/lib/base.en.conf | 4 ++ v2/src/lib/base.pt.conf | 4 ++ v2/src/lib/postamble.en.html | 7 ---- v2/src/lib/postamble.html | 36 +++++++++++++++++ v2/src/lib/postamble.pt.html | 5 --- v2/src/lib/preamble.en.html | 37 ----------------- v2/src/lib/preamble.html | 37 +++++++++++++++++ v2/src/lib/preamble.pt.html | 36 ----------------- 15 files changed, 142 insertions(+), 281 deletions(-) delete mode 100644 v2/src/lib/postamble.en.html create mode 100644 v2/src/lib/postamble.html delete mode 100644 v2/src/lib/postamble.pt.html delete mode 100644 v2/src/lib/preamble.en.html create mode 100644 v2/src/lib/preamble.html delete mode 100644 v2/src/lib/preamble.pt.html (limited to 'v2') diff --git a/v2/po/euandre.org.pot b/v2/po/euandre.org.pot index d3613c2..626385f 100644 --- a/v2/po/euandre.org.pot +++ b/v2/po/euandre.org.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2023-04-04 06:28-0300\n" +"POT-Creation-Date: 2023-04-04 13:10-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -22,51 +22,16 @@ msgid "date_fmt='%B %-d, %Y'" msgstr "" #. type: Plain text -#: src/lib/base.en.conf:3 +#: src/lib/base.en.conf:4 msgid "site_name=\"EuAndreh's website\"" msgstr "" -#. type: Content of:

-#: src/lib/postamble.en.html:2 -msgid "" -"Comment and see existing discussions | view source" -msgstr "" - -#. type: Attribute 'lang' of: -#: src/lib/preamble.en.html:2 -msgid "$lang" -msgstr "" - -#. type: Content of: -#: src/lib/preamble.en.html:9 -msgid "$(htmlesc \"$title\")" -msgstr "" - -#. type: Content of: <html><body><header><nav><ul> -#: src/lib/preamble.en.html:23 -msgid "" -"<a href=\"$lang_url\">EuAndreh</a> <a href=\"$(url-for " -"'about.html')\">About</a>" -msgstr "" - -#. type: Content of: <html><body><main><article><h1> -#: src/lib/preamble.en.html:32 -msgid "$title_html" -msgstr "" - -#. type: Content of: <html><body><main><article><p> -#: src/lib/preamble.en.html:35 -msgid "Posted on" -msgstr "" - -#. type: Content of: <html><body><main><article><p><time> -#: src/lib/preamble.en.html:35 -msgid "$date_formatted" +#. type: Plain text +#: src/lib/base.en.conf:6 +msgid "about='About'" msgstr "" -#. type: Content of: <html><body><main><article> -#: src/lib/preamble.en.html:37 -msgid "EOF" +#. type: Plain text +#: src/lib/base.en.conf:7 +msgid "about_url_name='about.html'" msgstr "" diff --git a/v2/po/po4a.cfg b/v2/po/po4a.cfg index 877f5a9..53014c6 100644 --- a/v2/po/po4a.cfg +++ b/v2/po/po4a.cfg @@ -3,5 +3,3 @@ [po_directory] po [type: text] src/lib/base.en.conf $lang:src/lib/base.$lang.conf -[type: xhtml] src/lib/postamble.en.html $lang:src/lib/postamble.$lang.html -[type: xhtml] src/lib/preamble.en.html $lang:src/lib/preamble.$lang.html diff --git a/v2/po/pt.po b/v2/po/pt.po index 2eb3ca6..4bc3a50 100644 --- a/v2/po/pt.po +++ b/v2/po/pt.po @@ -4,50 +4,16 @@ msgid "date_fmt='%B %-d, %Y'" msgstr "" #. type: Plain text -#: src/lib/base.en.conf:3 +#: src/lib/base.en.conf:4 msgid "site_name=\"EuAndreh's website\"" msgstr "" -#. type: Content of: <p> -#: src/lib/postamble.en.html:2 -msgid "" -"<a href=\"@mailto_uri@\">Comment</a> and see <a href=\"@discussions_url@" -"\">existing discussions</a> | <a href=\"@sourcecode_url@\">view source</a>" -msgstr "" - -#. type: Attribute 'lang' of: <html> -#: src/lib/preamble.en.html:2 -msgid "$lang" -msgstr "" - -#. type: Content of: <html><head><title> -#: src/lib/preamble.en.html:9 -msgid "$(htmlesc \"$title\")" -msgstr "" - -#. type: Content of: <html><body><header><nav><ul> -#: src/lib/preamble.en.html:23 -msgid "" -"<a href=\"$lang_url\">EuAndreh</a> <a href=\"$(url-for 'about." -"html')\">About</a>" -msgstr "" - -#. type: Content of: <html><body><main><article><h1> -#: src/lib/preamble.en.html:32 -msgid "$title_html" -msgstr "" - -#. type: Content of: <html><body><main><article><p> -#: src/lib/preamble.en.html:35 -msgid "Posted on" -msgstr "" - -#. type: Content of: <html><body><main><article><p><time> -#: src/lib/preamble.en.html:35 -msgid "$date_formatted" +#. type: Plain text +#: src/lib/base.en.conf:6 +msgid "about='About'" msgstr "" -#. type: Content of: <html><body><main><article> -#: src/lib/preamble.en.html:37 -msgid "EOF" +#. type: Plain text +#: src/lib/base.en.conf:7 +msgid "about_url_name='about.html'" msgstr "" diff --git a/v2/src/bin/url-for b/v2/src/bin/url-for index c31ff84..d4099bc 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 [-g] FILE url-for -h EOF } @@ -13,27 +13,28 @@ help() { cat <<-'EOF' Options: + -g global file, not specific to a single language -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. + Build an URL for the given FILE, without the $domain part, adding + the required $base_url. Examples: - Get the URL for "static/style.css", when BASE_URL is empty: + Get the URL for "about.html", when $base_url is "v2" and $lang is "en": - $ url-for 'static/style.css' - /static/style.css + $ url-for 'about.html' + /v2/en/about.html - Get the URL for "static/favicon.svg", when BASE_URL is "v2": + Get the URL for "static/favicon.svg", when $base_url is empty: - $ url-for 'static/favicon.svg' - /v2/static/favicon.svg + $ url-for -g 'static/favicon.svg' + /static/favicon.svg EOF } @@ -53,8 +54,12 @@ for flag in "$@"; do esac done -while getopts 'h' flag; do +GLOBAL=false +while getopts 'gh' flag; do case "$flag" in + g) + GLOBAL=true + ;; h) usage help @@ -72,8 +77,18 @@ shift $((OPTIND - 1)) FILE="${1:-}" -eval "$(assert_arg "$FILE" 'FILE')" +if [ "$FILE" = '/' ]; then + FILE='' +fi . src/lib/base-conf +# shellcheck source=/dev/null +. src/lib/base."${lang:?}".conf + +if [ "$GLOBAL" = true ]; then + L='' +else + L="${lang:?}/" +fi -printf '%s%s' "${base_url:-/}" "$FILE" +printf '%s%s%s' "${base_url:-/}" "$L" "$FILE" diff --git a/v2/src/development/genhtml.sh b/v2/src/development/genhtml.sh index 6839d23..8950b1d 100755 --- a/v2/src/development/genhtml.sh +++ b/v2/src/development/genhtml.sh @@ -193,93 +193,5 @@ emit_body() { add_headings_anchors } -if false; then - emit_body -fi - - - -# -# Main: generate the HTML to STDOUT. -# - -cat <<-EOF - <!DOCTYPE html> - <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="${style_url:?}" /> - <link rel="icon" type="image/svg+xml" href="${favicon_url:?}" /> - - <title>$$title_html - - - - - - - - - - -

- -
-
-
-
- \$(emit_body) -
-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 > $@ -# -# -# -#
-#
-# -# -# -# EOF - -# FIXMEs: -# - feeds -# - link to next and/or previous in -# - 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
 regex
-# - handle mixture of personal scripts
+envsubst < src/lib/preamble.html
+envsubst < src/lib/postamble.html
diff --git a/v2/src/development/getconf.sh b/v2/src/development/getconf.sh
index 4b615a8..aa90706 100755
--- a/v2/src/development/getconf.sh
+++ b/v2/src/development/getconf.sh
@@ -99,23 +99,32 @@ escape() {
 	# shellcheck source=/dev/null
 	. src/lib/base."$lang".conf
 
-	title="${title:-"$site_name"}"
+	if [ -z "${title:-}" ]; then
+		title="${site_name:?}"
+		printf 'title="%s"\n' "$(printf '%s' "$title" | escape)"
+	fi
+
+	if [ -z "${date:-}" ]; then
+		printf 'date_formatted="%s"\n' "$(LANG="$lang" date -d "${date:?}" +"${date_fmt:?}" | escape)"
+	fi
+
 	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 -g 'style.css')"
+	printf 'favicon_url="%s"\n' "$(url-for -g 'favicon.svg')"
 
-	printf 'style_url="%s"\n' "$(url-for 'style.css')"
-	printf 'favicon_url="%s"\n' "$(url-for 'favicon.svg')"
+	# FIXME: special treatment of root
+	printf 'homepage_url="%s"\n' "$(url-for '/')"
+	
+	printf 'about_url="%s"\n' "$(url-for "${about_url_name:?}")"
 
 	rm -f "$FILENAME".tmp
 } | grep . | sed 's|^|export |'
diff --git a/v2/src/lib/base-conf.in b/v2/src/lib/base-conf.in
index a33755a..c065807 100644
--- a/v2/src/lib/base-conf.in
+++ b/v2/src/lib/base-conf.in
@@ -1,9 +1,9 @@
-site_name="EuAndreh's website"
 domain='@DOMAIN@'
 email='@EMAIL@'
 base_url=''
-lang=en
 list_addr='~euandreh/public-inbox@lists.sr.ht'
 mailto_uri_prefix="mailto:$list_addr?Subject=Re%3A%20"
 discussions_url_prefix="https://lists.sr.ht/~euandreh/public-inbox?search="
 sourcecode_url_prefix="https://$domain/git/$domain/tree/"
+author='EuAndreh'
+lang='en'
diff --git a/v2/src/lib/base.en.conf b/v2/src/lib/base.en.conf
index 89344fb..6090d54 100644
--- a/v2/src/lib/base.en.conf
+++ b/v2/src/lib/base.en.conf
@@ -1,3 +1,7 @@
 date_fmt='%B %-d, %Y'
 
 site_name="EuAndreh's website"
+
+about='About'
+
+about_url_name='about.html'
diff --git a/v2/src/lib/base.pt.conf b/v2/src/lib/base.pt.conf
index 89344fb..6090d54 100644
--- a/v2/src/lib/base.pt.conf
+++ b/v2/src/lib/base.pt.conf
@@ -1,3 +1,7 @@
 date_fmt='%B %-d, %Y'
 
 site_name="EuAndreh's website"
+
+about='About'
+
+about_url_name='about.html'
diff --git a/v2/src/lib/postamble.en.html b/v2/src/lib/postamble.en.html
deleted file mode 100644
index 485d81c..0000000
--- a/v2/src/lib/postamble.en.html
+++ /dev/null
@@ -1,7 +0,0 @@
-

- Comment - and see - existing discussions - | - view source -

diff --git a/v2/src/lib/postamble.html b/v2/src/lib/postamble.html new file mode 100644 index 0000000..ada5524 --- /dev/null +++ b/v2/src/lib/postamble.html @@ -0,0 +1,36 @@ +

+ Comment + and see + existing discussions + | + view source +

+ + + + + + + + diff --git a/v2/src/lib/postamble.pt.html b/v2/src/lib/postamble.pt.html deleted file mode 100644 index 2e65735..0000000 --- a/v2/src/lib/postamble.pt.html +++ /dev/null @@ -1,5 +0,0 @@ -

- Comment and see existing discussions | view source -

diff --git a/v2/src/lib/preamble.en.html b/v2/src/lib/preamble.en.html deleted file mode 100644 index 9ea6780..0000000 --- a/v2/src/lib/preamble.en.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - $(htmlesc "$title") - - - - - - - - - - -
- -
-
-
-
-

- $title_html -

-

- Posted on -

-EOF diff --git a/v2/src/lib/preamble.html b/v2/src/lib/preamble.html new file mode 100644 index 0000000..3eac6ea --- /dev/null +++ b/v2/src/lib/preamble.html @@ -0,0 +1,37 @@ + + + + + + + + + $title_html + + + + + + + + + + +
+ +
+
+
+
+ dollar emit_body +

+ $title_html +

+

+ FIXME Posted on +

diff --git a/v2/src/lib/preamble.pt.html b/v2/src/lib/preamble.pt.html deleted file mode 100644 index 9800470..0000000 --- a/v2/src/lib/preamble.pt.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - $(htmlesc "$title") - - - - - - - - - - -
- -
-
-
-
-

- $title_html -

-

- Posted on -

-EOF -- cgit v1.2.3