-attachment() {
- local file="$(PATH "$1")"
-
- # TODO: deliver downscaled images, etc.
- if [ -f "$_DATA/pages/${file%/*}/#attachments/${file#*/}" ]; then
- FILE "$_DATA/pages/${file%/*}/#attachments/${file#*/}"
- elif [ -f "$_EXEC/pages/${file%/*}/#attachments/${file#*/}" ]; then
- FILE "$_EXEC/pages/${file%/*}/#attachments/${file#*/}"
- elif [ -d "$_DATA/pages/${file}/" -o -d "$_EXEC/pages/${file}" ]; then
- # path looks like a rogue page name (without trailing slash), so redirect
- REDIRECT "$_BASE/${file}/"
- else
- return 1
- fi
-}
-
-case "${PATH_INFO}" in
- /"[wiki]"/*)
- FILE "${_EXEC}/${PATH_INFO#/\[wiki\]}"
- ;;
- */)
- if [ -f "$_DATA/pages/$PATH_INFO/#page.md" \
- -o -f "$_EXEC/pages/$PATH_INFO/#page.md" ]; then
- theme_page "${PATH_INFO}"
- else
- theme_404
- fi
- ;;
- */"[attachment]"/*)
- : # TODO: Original attachment file
- ;;
- */"#"*)
- : # TODO: Invalid page name
- ;;
- *)
- attachment "${PATH_INFO}"
- ;;
-esac
+if [ "$(which git)" -a ! -f "$_DATA/.gitignore" ]; then
+ cat >"$_DATA/.gitignore" <<-EOF
+ users.db
+ serverkey
+ $([ "$REV_ATTACHMENTS" = true ] || printf %s "**/#attachments/")
+ **/#cache/
+ **/#page.lock
+ **/#page.*.cache
+ **/#page.*.cache.*
+ EOF
+ git init "$_DATA"
+ git -C "$_DATA" add .gitignore
+ git -C "$_DATA" commit -m 'initialization' -- .gitignore
+fi 1>&2
+
+for handler in "$_EXEC"/handlers/*; do
+ . "$handler" && break
+done
+
+if [ $? != 0 ]; then
+ export ERROR_MSG="The presented URL schema cannot be handled"
+ theme_error 400
+fi