]> git.plutz.net Git - shellwiki/blobdiff - acl.sh
gallery macro
[shellwiki] / acl.sh
diff --git a/acl.sh b/acl.sh
index 74fc8dc38419f9c556ff98e3882631ca709f6d8b..1b25d5ec78c93d7c33006aad9a0a329f7f9f3cb4 100755 (executable)
--- a/acl.sh
+++ b/acl.sh
@@ -1,7 +1,10 @@
 #!/bin/sh
 
+[ "$include_acl" ] && return 0
+include_acl="$0"
+
 # ACL_OVERRIDE="${ACL_OVERRIDE:-Admin:read,write}"
-ACL_DEFAULT="${ACL_DEFAULT:-All:read${BR}Known:read,write}"
+ACL_DEFAULT="${ACL_DEFAULT:-Known:read,write${BR}All:read}"
 
 acl_cachepath=''
 acl_collection=''
@@ -26,6 +29,8 @@ acl_collect(){
     [ "$path" = / ] && break
     path="${path%/*/}/"
 
+    # Do not use `mdfile` function here because of specialties
+    # in translation handler (`handlers/10_translations.sh`)
     if   [ -f "$_DATA/pages/$path/#page.md" ]; then
       pagefile="$_DATA/pages/$path/#page.md"
     elif [ -f "$_EXEC/pages/$path/#page.md" ]; then
@@ -34,16 +39,21 @@ acl_collect(){
       continue
     fi
 
-    n=20; while read -r head acl; do
-      if [ "$head" = "%acl" ]; then
-        acl_collection="${acl%${CR}}${BR}"
-        printf "%s\n" "${acl%${CR}}"
-        n=$((n+1))
-      fi
+    acl="$(sed -En '
+      s;\r$;;;
+      /^%acl([\t ]+.*)?$/bACL;
+      20q;
+      b;
+
+      :ACL
+      s;(%(acl)?)?[\t ]*;;
+      p; n; s;\r$;;;
+      /^(%[ \t]+|%acl[ \t]+|[ \t]+)[^ \t\r]+$/bACL;
+      /^(%[ \t]*|%acl[ \t]*)$/bACL;
+    ' <"$pagefile")"
 
-      n="$((n - 1))"
-      [ "$n" -eq 0 ] && break
-    done <"$pagefile"
+    printf %s\\n "${acl}"
+    acl_collection="${acl_collection}${acl}${BR}"
   done
 
   printf '%s\n' "$ACL_DEFAULT"