esac
}
-if [ "${PATH_INFO%/\[attachment\]/*}" != "${PATH_INFO}" ]; then
+if [ "${PATH_INFO%/\[attachment\]/}" != "${PATH_INFO}" ]; then
+ theme_attachments "${PATH_INFO%\[attachment\]/}"
+
+elif [ "${PATH_INFO%/\[attachment\]/*}" != "${PATH_INFO}" ]; then
attpath="${PATH_INFO%/\[attachment\]/*}/#attachments/${PATH_INFO##*/}"
if [ -f "$_DATA/pages/$attpath" ]; then
FILE "$_DATA/pages/$attpath"
#!/bin/sh
+. "$_EXEC/tools.sh"
+
theme_head(){
printf '
<meta name="viewport" content="width=device-width"/>
<link rel="stylesheet" type="text/css" href="%s/[.]/cgilite/common.css">
+ <link rel="stylesheet" type="text/css" href="%s/[.]/themes/default.css">
' "$_BASE"
}
local page="$1" title
title="${page%/}"; title="${title##*/}"
- # Important! Web Server response including newline newline
+ # Important! Web Server response including newline
printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
cat <<-EOF
<title>$(HTML "${title}")</title>
</head><body id="$(HTML "$page")">
$(theme_header)
- <main>$(wiki "$page" || printf 'Page not found')</main>
+ <main>
+ <ul class="pagemenu">
+ <li><a href="[edit]">Edit</a></li>
+ <li><a href="[attachment]/">Attachments</a></li>
+ </ul>
+ <article>
+ $(wiki "$page" || printf 'Page not found')
+ </article>
+ </main>
$(theme_footer)
</body></html>
EOF
EOF
}
+theme_attachments(){
+ local page="$1" title
+ title="${page%/}"; title="${title##*/}"
+
+ # Important! Web Server response including newline
+ printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
+
+ cat <<-EOF
+ <!DOCTYPE HTML>
+ <html><head>
+ $(theme_head)
+ <title>Attachments $(HTML "${title}")</title>
+ </head><body id="$(HTML "$page")[attachment]/">
+ $(theme_header)
+ <main>
+ <ul class="attachment list">
+ $(for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments"/*; do
+ [ "$file" = "$_EXEC/pages/$page/#attachments/${file##*/}" \
+ -a -f "$_DATA/pages/$page/#attachments/${file##*/}" ] && continue
+ stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue
+ size="${stat% *}" date="${stat#* }"
+
+ printf '<li><span class=name>%s</span>
+ <span class=size>%s</span><span class=date>%s</span></li>' \
+ "$(HTML "${file##*/}")" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
+ done)
+ </ul>
+ </main>
+ $(theme_footer)
+ </body></html>
+ EOF
+}
+
theme_login(){
theme_page '[wiki]/login/'
}