From: Paul Hänsch Date: Sun, 21 May 2023 13:42:42 +0000 (+0200) Subject: rewrite links to carry language tag, needs improvement X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=a88a2e833916c59ea6e99e9588543a58f02b9efe;p=shellwiki rewrite links to carry language tag, needs improvement --- 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 */:*/*):;; */:*)