]> git.plutz.net Git - shellwiki/commitdiff
rewrite links to carry language tag, needs improvement
authorPaul Hänsch <paul@plutz.net>
Sun, 21 May 2023 13:42:42 +0000 (15:42 +0200)
committerPaul Hänsch <paul@plutz.net>
Sun, 21 May 2023 13:42:42 +0000 (15:42 +0200)
handlers/10_translations.sh

index b9d6cb13db64e9cec2f4af0c7e4003e1e9b685b7..5ae3b0c5442332e553d34607da87a4f8c47e99c1 100755 (executable)
@@ -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
   */:*/*):;;
   */:*)