]> git.plutz.net Git - shellwiki/blobdiff - handlers/10_page.sh
Merge commit 'bfe458e83c0157879767976ba97bf95d1e27918c'
[shellwiki] / handlers / 10_page.sh
index 334df197d9694f72dfd8ccdfbc7c4fba69a96feb..f8cbbafaae166c9f141af7d548c18f3a5cba47b5 100755 (executable)
@@ -1,11 +1,11 @@
 #!/bin/sh
 
-CACHE_AGE=${CACHE_AGE:-1800}
+. "$_EXEC/cgilite/file.sh"
+. "$_EXEC/css.sh"
+
+CACHE_AGE=${CACHE_AGE:-300}
 export MD_MACROS="$_EXEC/macros"
 export MD_HTML="${MD_HTML:-false}"
-export WIKI_THEME=${WIKI_THEME:-default}
-
-. "$_EXEC/themes/${WIKI_THEME}.sh"
 
 wiki() {
   # Print content of a wiki page
@@ -26,8 +26,8 @@ wiki() {
     mkdir -p -- "$_DATA/pages/$page/"
     # Macros expect to find page directory as working dir
     ( cd -- "$_DATA/pages/$page/";
-      sed -E '1,20{ /^%[a-z]+/d; }' "$mdfile" \
-      | md |tee -- "${cache}.$$"
+      md <"$mdfile" \
+      | tee -- "${cache}.$$"
     )
     grep -q '^%nocache' "$mdfile" \
     && rm -- "${cache}.$$" \
@@ -37,6 +37,8 @@ wiki() {
 
 case "${PATH_INFO}" in
   /"[.]"/*)
+    # usually some file related to theme
+    # let file server handle errors
     FILE "${_EXEC}/${PATH_INFO#/\[.\]}"
     return 0
     ;;
@@ -50,11 +52,19 @@ case "${PATH_INFO}" in
     theme_error 400
     return 0
     ;;
-  */\[*\]/*)
+  */\[*\]/*|*/\[*\])
+    # looks like some kind of handler
     return 1
     ;;
   */)
-    theme_page "${PATH_INFO}"
+    if [ ! "$(mdfile "$PATH_INFO")" ]; then
+      theme_error 404
+    elif ! acl_read "$PATH_INFO"; then
+      theme_error 403
+    else
+      PAGE_CSS="$(css "${PATH_INFO}")"
+      theme_page "${PATH_INFO}"
+    fi
     return 0
     ;;
 esac