]> git.plutz.net Git - confetti/blobdiff - index.cgi
modular design
[confetti] / index.cgi
index e0bf125ec5c1ad6f4d7501d76cb5c3aaa09ae0f2..12f59b299db03c715539a229c965f0e63e73cc59 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -11,21 +11,36 @@ esac; done
 
 . "$_EXEC/cgilite/cgilite.sh"
 
-FILTER="$(GET filter)"
-ORDER="$(GET o |grep -m1 -axE 'firstname|lastname|bdate' || printf firstname)"
-# LISTSIZE="$(COOKIE pagesize |grep -m1 -axE '[1-9][0-9]*' || printf 50)"
-ITEM="$(PATH "${PATH_INFO#/}")"
+_PATH="$(PATH "/${PATH_INFO}")"
 ACTION="$(GET a)"
 
-if [ -d "${_EXEC}/${ITEM%%/*}/main.cgi" ]
-  . "${_EXEC}/${ITEM%%/*}/main.cgi"
-elif [ "$ITEM" = "/style.css" ]; then
-  . "$_EXEC/cgilite/file.sh"
-  [ -r "$_DATA/$ITEM" ] && FILE "$_DATA/$ITEM" \
-                        || FILE "$_EXEC/style.css"
-elif [ -d "${_EXEC}/${ITEM%%/*}" -a ! -x "${_EXEC}/$ITEM" ]
+yield_page() {
+  local class="$1" style="$2"
+  printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
+  { printf '
+       [html [head
+         [meta name="viewport" content="width=device-width"]
+         [link rel="stylesheet" type="text/css" href="/style.css"]
+    '
+    [ -n "$style" ] && printf '
+         [link rel="stylesheet" type="text/css" href="%s"]
+    ' "$style"
+    printf '
+       ] [body class="%s"
+    ' "$class"
+    cat
+    printf '] ]'
+  } \
+  | "${_EXEC}/cgilite/html-sh.sed"
+}
+
+if   [   -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}/main.cgi" ]; then
+  . "${_EXEC}/${_PATH}/main.cgi"
+elif [ ! -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}" ]; then
+  . "${_EXEC}/${_PATH}"
+elif [ ! -x "${_EXEC}/${_PATH}" -a -r "${_EXEC}/${_PATH}" ]; then
   . "$_EXEC/cgilite/file.sh"
-  FILE "${_EXEC}/$ITEM"
+  FILE "${_EXEC}/${_PATH}"
 else
   printf 'Status: 404 Not Found\r\nContent-Length: 0\r\n\r\n'
 fi