]> git.plutz.net Git - shellwiki/blob - themes/default.sh
Merge commit '11ee170457db15ac24e30a97c7fb555972da83b7'
[shellwiki] / themes / default.sh
1 #!/bin/sh
2
3 theme_head(){
4   printf '
5   <meta name="viewport" content="width=device-width"/>
6   <link rel="stylesheet" type="text/css" href="%s/[.]/cgilite/common.css">
7   ' "$_BASE"
8 }
9
10 theme_header(){
11   printf '<header>%s</header>' "$(wiki '[wiki]/header/')"
12 }
13
14 theme_footer(){
15   printf '<footer>%s</footer>' "$(wiki '[wiki]/footer/' ||echo No footer)"
16 }
17
18 theme_page(){
19   local page="$1" title
20   title="${page%/}"; title="${title##*/}"
21
22   # Important! Web Server response including newline newline
23   printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
24
25   cat <<-EOF
26         <!DOCTYPE HTML>
27         <html><head>
28           $(theme_head)
29           <title>$(HTML "${title}")</title>
30         </head><body id="$(HTML "$page")">
31           $(theme_header)
32           <main>$(wiki "$page" || printf 'Page not found')</main>
33           $(theme_footer)
34         </body></html>
35         EOF
36 }
37
38 theme_editor(){
39   local page="$1" title
40   title="${page%/}"; title="${title##*/}"
41
42   # Important! Web Server response including newline newline
43   printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
44
45   cat <<-EOF
46         <!DOCTYPE HTML>
47         <html><head>
48           $(theme_head)
49           <title>$(HTML "${title}")</title>
50         </head><body id="$(HTML "$page")" class="editor">
51           $(theme_header)
52           <main><form method=POST>
53             <textarea name=page>$(wiki_text "$page" |HTML)</textarea>
54             <button type=submit name=update value="$(HTML "$page")">Update</button>
55             <button type=submit name=cancel value="$(HTML "$page")">Cancel</button>
56           </form></main>
57           $(theme_footer)
58         </body></html>
59         EOF
60 }
61
62 theme_login(){
63   theme_page '[wiki]/login/'
64 }
65
66 theme_register(){
67   theme_page '[wiki]/register/'
68 }
69
70 theme_404(){
71   printf "%s\r\n" "Status: 404 Not Found"
72
73   theme_page '[wiki]/404/'
74 }