3 . "${_EXEC:-${0%/*}}/cgilite/cgilite.sh"
5 . "${_EXEC}/cgilite/session.sh"
6 . "${_EXEC}/cgilite/file.sh"
7 # . "$_EXEC"/cgilite/users.sh
9 . "${_EXEC}/themes/default.sh"
11 CACHE_AGE=${CACHE_AGE:-1800}
12 export MD_MACROS="$_EXEC/macros"
13 export MD_HTML="${MD_HTML:-false}"
15 if [ "$(which awk)" ]; then
16 md() { awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk"; }
17 elif [ "$(which busybox)" ]; then
18 md() { busybox awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk"; }
24 # Print content of a wiki page
25 # Get page from data or underlay dir, handle caching
26 local page="$(PATH "$1")" md cache cachetime
28 cache="$_DATA/pages/$page/#page.cache"
29 if [ -f "$_DATA/pages/$page/#page.md" ]; then
30 md="$_DATA/pages/$page/#page.md"
31 elif [ -f "$_EXEC/pages/$page/#page.md" ]; then
32 md="$_EXEC/pages/$page/#page.md"
37 cachetime="$(stat -c %Y -- "$md" "$cache" 2>/dev/null)"
39 if [ "${cachetime#*${BR}}" -gt "${cachetime%${BR}*}" \
40 -a "${cachetime#*${BR}}" -gt "$((_DATE - CACHE_AGE))" ]; then
43 mkdir -p -- "$_DATA/pages/$page/"
44 # Macros expect to find page directory as working dir
45 ( cd -- "$_DATA/pages/$page/";
46 md <"$md" |tee -- "${cache}.$$"
48 mv -- "${cache}.$$" "${cache}"
53 local file="$(PATH "$1")"
55 # TODO: deliver downscaled images, etc.
56 if [ -f "$_DATA/pages/${file%/*}/#attachments/${file#*/}" ]; then
57 FILE "$_DATA/pages/${file%/*}/#attachments/${file#*/}"
58 elif [ -f "$_EXEC/pages/${file%/*}/#attachments/${file#*/}" ]; then
59 FILE "$_EXEC/pages/${file%/*}/#attachments/${file#*/}"
60 elif [ -d "$_DATA/pages/${file}/" -o -d "$_EXEC/pages/${file}" ]; then
61 # path looks like a rogue page name (without trailing slash), so redirect
62 REDIRECT "$_BASE/${file}/"
68 case "${PATH_INFO}" in
70 FILE "${_EXEC}/${PATH_INFO#/\[wiki\]}"
73 if [ -f "$_DATA/pages/$PATH_INFO/#page.md" \
74 -o -f "$_EXEC/pages/$PATH_INFO/#page.md" ]; then
75 theme_page "${PATH_INFO}"
81 : # TODO: Original attachment file
84 : # TODO: Invalid page name
87 attachment "${PATH_INFO}"