From 5188614dbad08cce02ab53910d9252b0007f228f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Thu, 10 Mar 2022 17:34:01 +0100 Subject: [PATCH] default header and footer pages --- index.cgi | 31 ++++++++++++++++-- pages/[wiki]/footer/#page.md | 3 ++ pages/[wiki]/header/#page.md | 8 +++++ themes/default.sh | 61 +++++++++++++++++++++++++++++++----- 4 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 pages/[wiki]/footer/#page.md create mode 100644 pages/[wiki]/header/#page.md diff --git a/index.cgi b/index.cgi index 9d2ed3d..76f1bef 100755 --- a/index.cgi +++ b/index.cgi @@ -4,7 +4,7 @@ set -- nocookie . "${_EXEC}/cgilite/session.sh" . "${_EXEC}/cgilite/file.sh" -# . "$_EXEC"/cgilite/users.sh +. "${_EXEC}/cgilite/users.sh" . "${_EXEC}/themes/default.sh" @@ -20,6 +20,20 @@ else 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 @@ -66,8 +80,8 @@ attachment() { } case "${PATH_INFO}" in - /"[wiki]"/*) - FILE "${_EXEC}/${PATH_INFO#/\[wiki\]}" + /"[.]"/*) + FILE "${_EXEC}/${PATH_INFO#/\[.\]}" ;; */) if [ -f "$_DATA/pages/$PATH_INFO/#page.md" \ @@ -77,6 +91,17 @@ case "${PATH_INFO}" in theme_404 fi ;; + */"[edit]") + theme_editor "${PATH_INFO%\[edit\]}" + ;; + */"[login]") + [ "$USER_NAME" ] \ + && REDIRECT "./" \ + || theme_login + ;; + */"[register]") + theme_register + ;; */"[attachment]"/*) : # TODO: Original attachment file ;; diff --git a/pages/[wiki]/footer/#page.md b/pages/[wiki]/footer/#page.md new file mode 100644 index 0000000..da2b20f --- /dev/null +++ b/pages/[wiki]/footer/#page.md @@ -0,0 +1,3 @@ +---- +Shellwiki +Edit the Footer [here](/[wiki]/footer/[edit]) diff --git a/pages/[wiki]/header/#page.md b/pages/[wiki]/header/#page.md new file mode 100644 index 0000000..b5d60ff --- /dev/null +++ b/pages/[wiki]/header/#page.md @@ -0,0 +1,8 @@ +# Shellwiki + + * [Login]([login]) + * [Register]([register]) + +Edit the Header [here](/[wiki]/header/[edit]) + +---- diff --git a/themes/default.sh b/themes/default.sh index 6370166..56b57ae 100755 --- a/themes/default.sh +++ b/themes/default.sh @@ -1,27 +1,74 @@ #!/bin/sh -theme_404(){ - printf "%s\r\n" "Status: 404 Not Found" +theme_head(){ + printf ' + + + ' "$_BASE" +} - theme_page '/[404]/' +theme_header(){ + printf '
%s
' "$(wiki '[wiki]/header/')" +} + +theme_footer(){ + printf '' "$(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 - - + $(theme_head) $(HTML "${title}") -
+ $(theme_header)
$(wiki "$page" || printf 'Page not found')
- + $(theme_footer) 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 + + + $(theme_head) + $(HTML "${title}") + + $(theme_header) +
+ + + +
+ $(theme_footer) + + 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/' +} -- 2.39.2