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 source text of a wiki page
25 # Get page from data or underlay dir
26 local page="$(PATH "$1")"
28 if [ -f "$_DATA/pages/$page/#page.md" ]; then
29 cat -- "$_DATA/pages/$page/#page.md"
30 elif [ -f "$_EXEC/pages/$page/#page.md" ]; then
31 cat -- "$_EXEC/pages/$page/#page.md"
38 # Print content of a wiki page
39 # Get page from data or underlay dir, handle caching
40 local page="$(PATH "$1")" md cache cachetime
42 cache="$_DATA/pages/$page/#page.cache"
43 if [ -f "$_DATA/pages/$page/#page.md" ]; then
44 md="$_DATA/pages/$page/#page.md"
45 elif [ -f "$_EXEC/pages/$page/#page.md" ]; then
46 md="$_EXEC/pages/$page/#page.md"
51 cachetime="$(stat -c %Y -- "$md" "$cache" 2>/dev/null)"
53 if [ "${cachetime#*${BR}}" -gt "${cachetime%${BR}*}" \
54 -a "${cachetime#*${BR}}" -gt "$((_DATE - CACHE_AGE))" ]; then
57 mkdir -p -- "$_DATA/pages/$page/"
58 # Macros expect to find page directory as working dir
59 ( cd -- "$_DATA/pages/$page/";
60 md <"$md" |tee -- "${cache}.$$"
62 mv -- "${cache}.$$" "${cache}"
67 local file="$(PATH "$1")"
69 # TODO: deliver downscaled images, etc.
70 if [ -f "$_DATA/pages/${file%/*}/#attachments/${file#*/}" ]; then
71 FILE "$_DATA/pages/${file%/*}/#attachments/${file#*/}"
72 elif [ -f "$_EXEC/pages/${file%/*}/#attachments/${file#*/}" ]; then
73 FILE "$_EXEC/pages/${file%/*}/#attachments/${file#*/}"
74 elif [ -d "$_DATA/pages/${file}/" -o -d "$_EXEC/pages/${file}" ]; then
75 # path looks like a rogue page name (without trailing slash), so redirect
76 REDIRECT "$_BASE/${file}/"
82 . "$_EXEC/page_edit.sh"
84 case "${PATH_INFO}" in
86 FILE "${_EXEC}/${PATH_INFO#/\[.\]}"
89 if [ -f "$_DATA/pages/$PATH_INFO/#page.md" \
90 -o -f "$_EXEC/pages/$PATH_INFO/#page.md" ]; then
91 theme_page "${PATH_INFO}"
105 : # TODO: Original attachment file
108 : # TODO: Invalid page name
111 attachment "${PATH_INFO}"