set -- nocookie
. "${_EXEC}/cgilite/session.sh"
. "${_EXEC}/cgilite/file.sh"
-# . "$_EXEC"/cgilite/users.sh
+. "${_EXEC}/cgilite/users.sh"
. "${_EXEC}/themes/default.sh"
md() { cat; }
fi
+wiki_text() {
+ # Print source text of a wiki page
+ # Get page from data or underlay dir
+ local page="$(PATH "$1")"
+
+ if [ -f "$_DATA/pages/$page/#page.md" ]; then
+ cat -- "$_DATA/pages/$page/#page.md"
+ elif [ -f "$_EXEC/pages/$page/#page.md" ]; then
+ cat -- "$_EXEC/pages/$page/#page.md"
+ else
+ return 1
+ fi
+}
+
wiki() {
# Print content of a wiki page
# Get page from data or underlay dir, handle caching
}
case "${PATH_INFO}" in
- /"[wiki]"/*)
- FILE "${_EXEC}/${PATH_INFO#/\[wiki\]}"
+ /"[.]"/*)
+ FILE "${_EXEC}/${PATH_INFO#/\[.\]}"
;;
*/)
if [ -f "$_DATA/pages/$PATH_INFO/#page.md" \
theme_404
fi
;;
+ */"[edit]")
+ theme_editor "${PATH_INFO%\[edit\]}"
+ ;;
+ */"[login]")
+ [ "$USER_NAME" ] \
+ && REDIRECT "./" \
+ || theme_login
+ ;;
+ */"[register]")
+ theme_register
+ ;;
*/"[attachment]"/*)
: # TODO: Original attachment file
;;
#!/bin/sh
-theme_404(){
- printf "%s\r\n" "Status: 404 Not Found"
+theme_head(){
+ printf '
+ <meta name="viewport" content="width=device-width"/>
+ <link rel="stylesheet" type="text/css" href="%s/[.]/cgilite/common.css">
+ ' "$_BASE"
+}
- theme_page '/[404]/'
+theme_header(){
+ printf '<header>%s</header>' "$(wiki '[wiki]/header/')"
+}
+
+theme_footer(){
+ printf '<footer>%s</footer>' "$(wiki '[wiki]/footer/' ||echo No footer)"
}
theme_page(){
local page="$1" title
title="${page%/}"; title="${title##*/}"
+ # Important! Web Server response including newline newline
printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
cat <<-EOF
<!DOCTYPE HTML>
<html><head>
- <meta name="viewport" content="width=device-width"/>
- <link rel="stylesheet" type="text/css" href="$_BASE/[wiki]/cgilite/common.css">
+ $(theme_head)
<title>$(HTML "${title}")</title>
</head><body id="$(HTML "$page")">
- <header></header>
+ $(theme_header)
<main>$(wiki "$page" || printf 'Page not found')</main>
- <footer></footer>
+ $(theme_footer)
</body></html>
EOF
}
+
+theme_editor(){
+ local page="$1" title
+ title="${page%/}"; title="${title##*/}"
+
+ # Important! Web Server response including newline newline
+ printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
+
+ cat <<-EOF
+ <!DOCTYPE HTML>
+ <html><head>
+ $(theme_head)
+ <title>$(HTML "${title}")</title>
+ </head><body id="$(HTML "$page")" class="editor">
+ $(theme_header)
+ <main><form method=POST>
+ <textarea name=page>$(wiki_text "$page" |HTML)</textarea>
+ <button type=submit name=update value="$(HTML "$page")">Update</button>
+ <button type=submit name=cancel value="$(HTML "$page")">Cancel</button>
+ </form></main>
+ $(theme_footer)
+ </body></html>
+ EOF
+}
+
+theme_login(){
+ theme_page '[wiki]/login/'
+}
+
+theme_register(){
+ theme_page '[wiki]/register/'
+}
+
+theme_404(){
+ printf "%s\r\n" "Status: 404 Not Found"
+
+ theme_page '[wiki]/404/'
+}