3 . "${_EXEC:-${0%/*}}/cgilite/cgilite.sh"
4 . "${_EXEC}/cgilite/session.sh"
5 . "${_EXEC}/cgilite/file.sh"
6 . "${_EXEC}/cgilite/users.sh"
8 . "${_EXEC}/themes/default.sh"
10 CACHE_AGE=${CACHE_AGE:-1800}
11 export MD_MACROS="$_EXEC/macros"
12 export MD_HTML="${MD_HTML:-false}"
14 if [ "$(which awk)" ]; then
15 md() { awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk"; }
16 elif [ "$(which busybox)" ]; then
17 md() { busybox awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk"; }
23 # Print source text of a wiki page
24 # Get page from data or underlay dir
25 local page="$(PATH "$1")"
27 if [ -f "$_DATA/pages/$page/#page.md" ]; then
28 cat -- "$_DATA/pages/$page/#page.md"
29 elif [ -f "$_EXEC/pages/$page/#page.md" ]; then
30 cat -- "$_EXEC/pages/$page/#page.md"
37 # Print content of a wiki page
38 # Get page from data or underlay dir, handle caching
39 local page="$(PATH "$1")" md cache cachetime
41 cache="$_DATA/pages/$page/#page.cache"
42 if [ -f "$_DATA/pages/$page/#page.md" ]; then
43 md="$_DATA/pages/$page/#page.md"
44 elif [ -f "$_EXEC/pages/$page/#page.md" ]; then
45 md="$_EXEC/pages/$page/#page.md"
50 cachetime="$(stat -c %Y -- "$md" "$cache" 2>/dev/null)"
52 if [ "${cachetime#*${BR}}" -gt "${cachetime%${BR}*}" \
53 -a "${cachetime#*${BR}}" -gt "$((_DATE - CACHE_AGE))" ]; then
56 mkdir -p -- "$_DATA/pages/$page/"
57 # Macros expect to find page directory as working dir
58 ( cd -- "$_DATA/pages/$page/";
59 md <"$md" |tee -- "${cache}.$$"
61 mv -- "${cache}.$$" "${cache}"
66 local file="$(PATH "$1")"
68 # TODO: deliver downscaled images, etc.
69 if [ -f "$_DATA/pages/${file%/*}/#attachments/${file#*/}" ]; then
70 FILE "$_DATA/pages/${file%/*}/#attachments/${file#*/}"
71 elif [ -f "$_EXEC/pages/${file%/*}/#attachments/${file#*/}" ]; then
72 FILE "$_EXEC/pages/${file%/*}/#attachments/${file#*/}"
73 elif [ -d "$_DATA/pages/${file}/" -o -d "$_EXEC/pages/${file}" ]; then
74 # path looks like a rogue page name (without trailing slash), so redirect
75 REDIRECT "$_BASE/${file}/"
81 . "$_EXEC/page_edit.sh"
83 case "${PATH_INFO}" in
85 FILE "${_EXEC}/${PATH_INFO#/\[.\]}"
88 if [ -f "$_DATA/pages/$PATH_INFO/#page.md" \
89 -o -f "$_EXEC/pages/$PATH_INFO/#page.md" ]; then
90 theme_page "${PATH_INFO}"
104 : # TODO: Original attachment file
107 : # TODO: Invalid page name
110 attachment "${PATH_INFO}"