aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-04-09 18:59:09 -0300
committerEuAndreh <eu@euandre.org>2023-04-09 19:05:39 -0300
commit19a8b995c59cce5315e1d121054f9c27aad5c960 (patch)
treef2c2d83751245004beed21b31d973c1d412cd026
parentv2: CSS dark mode, including SVGs (diff)
downloadeuandre.org-19a8b995c59cce5315e1d121054f9c27aad5c960.tar.gz
euandre.org-19a8b995c59cce5315e1d121054f9c27aad5c960.tar.xz
v2: Support translated alternates in <nav>
Diffstat (limited to '')
-rw-r--r--TODOs.md10
-rw-r--r--v2/.gitignore1
-rw-r--r--v2/dynamic.mk8
-rw-r--r--v2/po/euandre.org.pot41
-rw-r--r--v2/po/pt.po61
-rwxr-xr-xv2/src/bin/conf18
-rwxr-xr-xv2/src/bin/i18n87
-rwxr-xr-xv2/src/bin/index15
-rwxr-xr-xv2/src/bin/url-for39
-rw-r--r--v2/src/content/style.css23
-rw-r--r--v2/src/lib/base.en.conf6
-rw-r--r--v2/src/lib/base.pt.conf6
-rw-r--r--v2/src/lib/preamble.html19
13 files changed, 282 insertions, 52 deletions
diff --git a/TODOs.md b/TODOs.md
index 1512cbe..a97f202 100644
--- a/TODOs.md
+++ b/TODOs.md
@@ -529,14 +529,16 @@ Move brinquedoteca out of jekyll?
FIXMEs:
+- DIY:
+ - CommonMark parser
+ - envsubst, with errors on undefined variables
+ - `date -d` isn't POSIX: simple replacement
+- translation not coming from english (like pt -> fr)
- how to use tmp fd over tmpfile?
-- DIY CommonMark parser
-- DIY envsubst, with errors on undefined variables
-- `date -d` isn't POSIX: DIY simple replacement
- po4a for markdown...
- render slides
- sitemap
- shrink CSS
- link to next and/or previous in <head>
-- link to translations
+- link to translations in <head>
- build makemake output in parallel
diff --git a/v2/.gitignore b/v2/.gitignore
index 9ad29bd..fe51060 100644
--- a/v2/.gitignore
+++ b/v2/.gitignore
@@ -14,6 +14,7 @@
/src/content/**/*.content
/src/content/**/*.html
/src/content/**/*.extrahtml
+/src/content/**/*.i18n
/src/content/**/*.md.tmp
/src/content/**/*.htmlbody
/src/content/**/*.snippets
diff --git a/v2/dynamic.mk b/v2/dynamic.mk
index e4f349d..ac06c20 100644
--- a/v2/dynamic.mk
+++ b/v2/dynamic.mk
@@ -11,7 +11,9 @@ include generated.mk
.page.md:
+ ln -f $<.i18n $@.i18n
ln -f $< $@
+ touch $@ $@.i18n
.md.content:
awk 'sep >= 2; /^---$$/ {sep++}' < $< > $@
@@ -44,6 +46,7 @@ all: public
$(all-generated.conf) $(all-generated.content): $(non-content)
+$(all-generated.conf) $(pages-mds): i18n-index.sentinel
$(all-generated.conf): src/lib/base.conf src/lib/generated.conf
src/lib/generated.conf: src/bin/conf $(svgs)
@@ -58,6 +61,10 @@ $(all-generated.index): src/lib/generated.conf
$(all-generated.xml):
feed $@
+i18n-index.sentinel: po/i18n.mappings
+ i18n < po/i18n.mappings
+ touch $@
+
clean:
rm -rf \
$(all-generated) $(pages-mds) $(svgs) public/ *.sentinel \
@@ -68,6 +75,7 @@ clean:
src/content/*/*.extrahtml src/content/*/*/*.extrahtml \
src/content/*/*.extrafeeds src/content/*/*/*.extrafeeds \
src/content/*/*.html.*.txt src/content/*/*/*.html.*.txt \
+ src/content/*/*.i18n src/content/*/*/*.i18n \
src/content/*/*.sortdata src/content/*/*/*.sortdata \
src/content/*/feed.*.xml src/content/*/*/feed.*.xml \
src/lib/generated.conf src/lib/generated.*.conf po/*.mo \
diff --git a/v2/po/euandre.org.pot b/v2/po/euandre.org.pot
index c90685c..0a63aab 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-08 15:21-0300\n"
+"POT-Creation-Date: 2023-04-09 18:56-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -110,46 +110,63 @@ msgstr ""
#. type: Plain text
#: src/lib/base.en.conf:27
+msgid "export index__url=\"$(url-for \"$lang/$(coll2path \"$lang\" article)\")\""
+msgstr ""
+
+#. type: Plain text
+#: src/lib/base.en.conf:29
msgid "export feed__title=\"EuAndreh's articles\""
msgstr ""
#. type: Plain text
-#: src/lib/base.en.conf:30
+#: src/lib/base.en.conf:32
msgid "export index_pastebin_title='Pastebins'"
msgstr ""
#. type: Plain text
-#: src/lib/base.en.conf:32
+#: src/lib/base.en.conf:34
msgid "export index_recent_pastebin_title='Pastebins listing'"
msgstr ""
#. type: Plain text
-#: src/lib/base.en.conf:34
+#: src/lib/base.en.conf:36
msgid "export index_category_pastebin_title='Pastebins by category'"
msgstr ""
#. type: Plain text
-#: src/lib/base.en.conf:36
+#: src/lib/base.en.conf:38
+msgid ""
+"export index_pastebin_url=\"$(url-for \"$lang/$(coll2path \"$lang\" "
+"pastebin)\")\""
+msgstr ""
+
+#. type: Plain text
+#: src/lib/base.en.conf:40
msgid "export feed_pastebin_title=\"EuAndreh's pastebins\""
msgstr ""
#. type: Plain text
-#: src/lib/base.en.conf:39
+#: src/lib/base.en.conf:43
msgid "export index_til_title='TIL'"
msgstr ""
#. type: Plain text
-#: src/lib/base.en.conf:41
+#: src/lib/base.en.conf:45
msgid "export index_recent_til_title='TIL listing'"
msgstr ""
#. type: Plain text
-#: src/lib/base.en.conf:43
+#: src/lib/base.en.conf:47
msgid "export index_category_til_title='TIL by category'"
msgstr ""
#. type: Plain text
-#: src/lib/base.en.conf:44
+#: src/lib/base.en.conf:49
+msgid "export index_til_url=\"$(url-for \"$lang/$(coll2path \"$lang\" til)\")\""
+msgstr ""
+
+#. type: Plain text
+#: src/lib/base.en.conf:50
msgid "export feed_til_title=\"EuAndreh's TIL\""
msgstr ""
@@ -202,7 +219,7 @@ msgid "$formatted_update"
msgstr ""
#. type: Plain text
-#: src/content/en/about.md:1 src/content/en/about.md:5
+#: src/content/en/about.page:1 src/content/en/about.page:5
#: src/content/en/pastebin/sicp-exercise-3-19.md:1
#: src/content/en/pastebin/sicp-exercise-3-19.md:9
#: src/content/en/til/lisp-three-way-conditional.md:1
@@ -212,12 +229,12 @@ msgid "---\n"
msgstr ""
#. type: Plain text
-#: src/content/en/about.md:4
+#: src/content/en/about.page:4
msgid "title: About"
msgstr ""
#. type: Plain text
-#: src/content/en/about.md:7
+#: src/content/en/about.page:7
msgid "It's all about me, baby!"
msgstr ""
diff --git a/v2/po/pt.po b/v2/po/pt.po
index bee1fc3..ea2a371 100644
--- a/v2/po/pt.po
+++ b/v2/po/pt.po
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
-"POT-Creation-Date: 2023-04-08 15:21-0300\n"
+"POT-Creation-Date: 2023-04-09 18:56-0300\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -105,46 +105,83 @@ msgstr "export index_category__title='Artigos por categoria'"
#. type: Plain text
#: src/lib/base.en.conf:27
+#, fuzzy
+#| msgid ""
+#| "export index_pastebin_url=\"$(url-for \"$lang/$(coll2path \"$lang\" "
+#| "'pastebin')\")\""
+msgid ""
+"export index__url=\"$(url-for \"$lang/$(coll2path \"$lang\" article)\")\""
+msgstr ""
+"export index_pastebin_url=\"$(url-for \"$lang/$(coll2path \"$lang\" "
+"'pastebin')\")\""
+
+#. type: Plain text
+#: src/lib/base.en.conf:29
msgid "export feed__title=\"EuAndreh's articles\""
msgstr "export feed__title=\"Artigos do EuAndreh\""
#. type: Plain text
-#: src/lib/base.en.conf:30
+#: src/lib/base.en.conf:32
msgid "export index_pastebin_title='Pastebins'"
msgstr ""
#. type: Plain text
-#: src/lib/base.en.conf:32
+#: src/lib/base.en.conf:34
msgid "export index_recent_pastebin_title='Pastebins listing'"
msgstr ""
#. type: Plain text
-#: src/lib/base.en.conf:34
+#: src/lib/base.en.conf:36
msgid "export index_category_pastebin_title='Pastebins by category'"
msgstr ""
#. type: Plain text
-#: src/lib/base.en.conf:36
+#: src/lib/base.en.conf:38
+#, fuzzy
+#| msgid ""
+#| "export index_pastebin_url=\"$(url-for \"$lang/$(coll2path \"$lang\" "
+#| "'pastebin')\")\""
+msgid ""
+"export index_pastebin_url=\"$(url-for \"$lang/$(coll2path \"$lang\" "
+"pastebin)\")\""
+msgstr ""
+"export index_pastebin_url=\"$(url-for \"$lang/$(coll2path \"$lang\" "
+"'pastebin')\")\""
+
+#. type: Plain text
+#: src/lib/base.en.conf:40
msgid "export feed_pastebin_title=\"EuAndreh's pastebins\""
msgstr ""
#. type: Plain text
-#: src/lib/base.en.conf:39
+#: src/lib/base.en.conf:43
msgid "export index_til_title='TIL'"
msgstr "export index_til_title='HEA'"
#. type: Plain text
-#: src/lib/base.en.conf:41
+#: src/lib/base.en.conf:45
msgid "export index_recent_til_title='TIL listing'"
msgstr "export index_recent_til_title='HEA recentes'"
#. type: Plain text
-#: src/lib/base.en.conf:43
+#: src/lib/base.en.conf:47
msgid "export index_category_til_title='TIL by category'"
msgstr "export index_category_til_title='HEA por categoria'"
#. type: Plain text
-#: src/lib/base.en.conf:44
+#: src/lib/base.en.conf:49
+#, fuzzy
+#| msgid ""
+#| "export index_pastebin_url=\"$(url-for \"$lang/$(coll2path \"$lang\" "
+#| "'pastebin')\")\""
+msgid ""
+"export index_til_url=\"$(url-for \"$lang/$(coll2path \"$lang\" til)\")\""
+msgstr ""
+"export index_pastebin_url=\"$(url-for \"$lang/$(coll2path \"$lang\" "
+"'pastebin')\")\""
+
+#. type: Plain text
+#: src/lib/base.en.conf:50
msgid "export feed_til_title=\"EuAndreh's TIL\""
msgstr "export feed_til_title=\"HEA do EuAndreh\""
@@ -196,7 +233,7 @@ msgid "$formatted_update"
msgstr ""
#. type: Plain text
-#: src/content/en/about.md:1 src/content/en/about.md:5
+#: src/content/en/about.page:1 src/content/en/about.page:5
#: src/content/en/pastebin/sicp-exercise-3-19.md:1
#: src/content/en/pastebin/sicp-exercise-3-19.md:9
#: src/content/en/til/lisp-three-way-conditional.md:1
@@ -206,12 +243,12 @@ msgid "---\n"
msgstr ""
#. type: Plain text
-#: src/content/en/about.md:4
+#: src/content/en/about.page:4
msgid "title: About"
msgstr ""
#. type: Plain text
-#: src/content/en/about.md:7
+#: src/content/en/about.page:7
msgid "It's all about me, baby!"
msgstr ""
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
diff --git a/v2/src/content/style.css b/v2/src/content/style.css
index 7797065..a4a635f 100644
--- a/v2/src/content/style.css
+++ b/v2/src/content/style.css
@@ -50,8 +50,15 @@ a:visited {
/* Navigation header */
-nav a {
+nav {
+ margin-top: 8px;
+}
+
+nav a, nav a:visited {
color: var(--nav-color);
+}
+
+nav a {
font-size: 18px;
margin: 12px;
text-decoration: none;
@@ -61,9 +68,21 @@ nav ul, nav li {
display: inline;
}
-nav ul li a {
+nav ul.translation-list a, nav ul.translation-list a:visited {
color: var(--color);
font-size: 14px;
+}
+
+nav ul.translation-list {
+ display: flex;
+ justify-content: flex-end;
+ font-size: 16px;
+ margin: 0;
+ padding: 0;
+}
+
+nav ul li a {
+ font-size: 18px;
margin: 6px;
}
diff --git a/v2/src/lib/base.en.conf b/v2/src/lib/base.en.conf
index bc90b10..4eff237 100644
--- a/v2/src/lib/base.en.conf
+++ b/v2/src/lib/base.en.conf
@@ -23,6 +23,8 @@ export index_recent__title='Recent articles'
export index_category__title='Articles by category'
+export index__url="$(url-for "$lang/$(coll2path "$lang" article)")"
+
export feed__title="EuAndreh's articles"
@@ -32,6 +34,8 @@ export index_recent_pastebin_title='Pastebins listing'
export index_category_pastebin_title='Pastebins by category'
+export index_pastebin_url="$(url-for "$lang/$(coll2path "$lang" pastebin)")"
+
export feed_pastebin_title="EuAndreh's pastebins"
@@ -41,4 +45,6 @@ export index_recent_til_title='TIL listing'
export index_category_til_title='TIL by category'
+export index_til_url="$(url-for "$lang/$(coll2path "$lang" til)")"
+
export feed_til_title="EuAndreh's TIL"
diff --git a/v2/src/lib/base.pt.conf b/v2/src/lib/base.pt.conf
index 5703bed..8c9f7c9 100644
--- a/v2/src/lib/base.pt.conf
+++ b/v2/src/lib/base.pt.conf
@@ -23,6 +23,8 @@ export index_recent__title='Artigos recentes'
export index_category__title='Artigos por categoria'
+export index__url="$(url-for "$lang/$(coll2path "$lang" article)")"
+
export feed__title="Artigos do EuAndreh"
@@ -32,6 +34,8 @@ export index_recent_pastebin_title='Pastebins listing'
export index_category_pastebin_title='Pastebins by category'
+export index_pastebin_url="$(url-for "$lang/$(coll2path "$lang" pastebin)")"
+
export feed_pastebin_title="EuAndreh's pastebins"
@@ -41,4 +45,6 @@ export index_recent_til_title='HEA recentes'
export index_category_til_title='HEA por categoria'
+export index_til_url="$(url-for "$lang/$(coll2path "$lang" til)")"
+
export feed_til_title="HEA do EuAndreh"
diff --git a/v2/src/lib/preamble.html b/v2/src/lib/preamble.html
index fc19961..1649bdd 100644
--- a/v2/src/lib/preamble.html
+++ b/v2/src/lib/preamble.html
@@ -19,10 +19,23 @@
<body>
<header>
<nav>
- <ul>
- <a href="$homepage_url">$author</a>
- <a href="$about_url">$about</a>
+ <ul class="main-navigation-links">
+ <li>
+ <a href="$homepage_url">$author</a>
+ </li>
+ <li>
+ <a href="$about_url">$about</a>
+ </li>
</ul>
+ <ul class="collections-navigation-links">
+ <li>
+ <a href="$index_til_url">$index_til_title</a>
+ </li>
+ <li>
+ <a href="$index_pastebin_url">$index_pastebin_title</a>
+ </li>
+ </ul>
+$translations_html
</nav>
<hr />
</header>