From a88a2e833916c59ea6e99e9588543a58f02b9efe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sun, 21 May 2023 15:42:42 +0200 Subject: [PATCH] rewrite links to carry language tag, needs improvement --- handlers/10_translations.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/handlers/10_translations.sh b/handlers/10_translations.sh index b9d6cb1..5ae3b0c 100755 --- a/handlers/10_translations.sh +++ b/handlers/10_translations.sh @@ -5,7 +5,7 @@ export LANGUAGE_DEFAULT="${LANGUAGE_DEFAULT:-en}" export HTTP_REFERER="${HTTP_REFERER:-$(HEADER Referer)}" -export LANGUAGE='' +export LANGUAGE ERROR_MSG mdfile(){ # Override mdfile Selection from tools.sh @@ -40,6 +40,23 @@ mdfile(){ # by printf when stdout was closed } +# UGLY! UGLY! UGLY! +# Override markdown processor from `tools.sh` to add link suffixes +# -> better implement a parser stack, i.e. pipeline markdown + other parser plugins +if [ "$(which awk)" ]; then + md() { + awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk" \ + | sed -E 's;(<[^>]+ )href="((/[^"/]+|[^"/]+[^:/]|)/([^"/]+/)*)"([^>]*>);\1href="\2:'"${LANGUAGE}"'"\5;g' + } +elif [ "$(which busybox)" ]; then + md() { + busybox awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk" \ + | sed -E 's;(<[^>]+ )href="((/[^"/]+|[^"/]+[^:/]|)/([^"/]+/)*)"([^>]*>);\1href="\2:'"${LANGUAGE}"'"\5;g' + } +else + md() { cat; } +fi + case ${HTTP_REFERER} in */:*/*):;; */:*) -- 2.39.2