aboutsummaryrefslogtreecommitdiff
path: root/v2/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-04-10 14:12:12 -0300
committerEuAndreh <eu@euandre.org>2023-04-10 14:12:37 -0300
commitfc794694b1d83d6856b36ea08df69c2a0861d030 (patch)
tree752cb386042281cfcc72836623af733c3253bff2 /v2/src
parentv2: Support translated alternates in <nav> (diff)
downloadeuandre.org-fc794694b1d83d6856b36ea08df69c2a0861d030.tar.gz
euandre.org-fc794694b1d83d6856b36ea08df69c2a0861d030.tar.xz
v2: <link /> to translated version in <head />
Diffstat (limited to '')
-rwxr-xr-xv2/src/bin/conf12
-rwxr-xr-xv2/src/bin/i18n18
-rwxr-xr-xv2/src/bin/index12
-rw-r--r--v2/src/lib/preamble.html10
4 files changed, 37 insertions, 15 deletions
diff --git a/v2/src/bin/conf b/v2/src/bin/conf
index e4dba61..3b56dbd 100755
--- a/v2/src/bin/conf
+++ b/v2/src/bin/conf
@@ -155,17 +155,21 @@ if [ -z "${title:-}" ]; then
fi
if [ -r "$FILENAME".i18n ]; then
- translations="$(cat <<-EOF
+ translations_head="$(awk -F: -v lang="$lang" '$1 != lang{
+ printf " <link rel=\"alternate\" type=\"text/html\" href=\"%s\" hreflang=\"%s\" />\n",
+ $3, $1
+ }' "$FILENAME".i18n)"
+ translations_body="$(cat <<-EOF
<ul class="translation-list">
$(awk -F: '{
- "url-for " $2 | getline url
printf " <li><a href=\"%s\">%s</a></li>\n",
- url, $1
+ $3, $1
}' "$FILENAME".i18n)
</ul>
EOF
)"
- printf 'export translations_html="%s"\n' "$(shesc "$translations")"
+ printf 'export translations_head_html="%s"\n' "$(shesc "$translations_head")"
+ printf 'export translations_body_html="%s"\n' "$(shesc "$translations_body")"
fi
if [ -n "${date:-}" ]; then
diff --git a/v2/src/bin/i18n b/v2/src/bin/i18n
index 76e07e7..30404eb 100755
--- a/v2/src/bin/i18n
+++ b/v2/src/bin/i18n
@@ -75,11 +75,21 @@ awk '
END {
for (k1 in idx) {
+ split(idx[k1][0], b, /:/)
+ base = b[2] ".i18n"
for (k2 in idx[k1]) {
- split(idx[k1][k2], a, /:/)
- file = a[2] ".i18n"
- for (k3 in idx[k1]) {
- print idx[k1][k3] > file
+ split(idx[k1][k2], f, /:/)
+ file = f[2] ".i18n"
+ if (k2 == 0) {
+ for (k3 in idx[k1]) {
+ "url-for " f[2] | getline url
+ print idx[k1][k3] ":" url > file
+ }
+ } else {
+ ret = system("cp " base " " file)
+ if (ret) {
+ exit ret
+ }
}
}
}
diff --git a/v2/src/bin/index b/v2/src/bin/index
index 553cc27..36abd2e 100755
--- a/v2/src/bin/index
+++ b/v2/src/bin/index
@@ -85,7 +85,15 @@ 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
+translations_head_html="$(langs |
+ awk -v lang="${lang:?}" -v coll="$collection" '$0 != lang {
+ "coll2path " $0 " " coll | getline coll_path
+ "url-for " $0 "/" coll_path | getline url
+ printf " <link rel=\"alternate\" type=\"text/html\" href=\"%s\" hreflang=\"%s\" />\n",
+ url, $0
+ }'
+)"
+translations_body_html="$(cat <<-EOF
<ul class="translation-list">
$(langs | awk -v coll="$collection" '{
"coll2path " $0 " " coll | getline coll_path
@@ -95,7 +103,7 @@ translations_html="$(cat <<-EOF
</ul>
EOF
)"
-export translations_html
+export translations_head_html translations_body_html
diff --git a/v2/src/lib/preamble.html b/v2/src/lib/preamble.html
index 1649bdd..c1e0592 100644
--- a/v2/src/lib/preamble.html
+++ b/v2/src/lib/preamble.html
@@ -5,16 +5,16 @@
<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="$icon_favicon_url" />
+ <link rel="canonical" type="text/html" href="$url_absolute" />
+$translations_head_html
<title>$title_html</title>
- <meta name="author" content="$author" />
+ <meta name="author" content="$author" />
+ <meta property="og:url" content="$url_absolute" />
<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_absolute" />
- <meta property="og:url" content="$url_absolute" />
</head>
<body>
<header>
@@ -35,7 +35,7 @@
<a href="$index_pastebin_url">$index_pastebin_title</a>
</li>
</ul>
-$translations_html
+$translations_body_html
</nav>
<hr />
</header>