From: Paul Hänsch Date: Tue, 17 May 2022 21:25:22 +0000 (+0200) Subject: move functions to tools X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=277d06327a184eb1fb72ba46fd8a3194c9c37362;p=shellwiki move functions to tools --- diff --git a/index.cgi b/index.cgi index 0c7e914..8975cca 100755 --- a/index.cgi +++ b/index.cgi @@ -4,20 +4,9 @@ . "${_EXEC}/cgilite/session.sh" . "${_EXEC}/cgilite/file.sh" . "${_EXEC}/cgilite/users.sh" +. "${_EXEC}/tools.sh" . "${_EXEC}/acl.sh" -mdfile(){ - local page="$(PATH "$1")" - - if [ -f "$_DATA/pages/$page/#page.md" ]; then - printf %s\\n "$_DATA/pages/$page/#page.md" - elif [ -f "$_EXEC/pages/$page/#page.md" ]; then - printf %s\\n "$_EXEC/pages/$page/#page.md" - else - return 1 - fi -} - wiki_text() { # Print source text of a wiki page # Get page from data or underlay dir diff --git a/tools.sh b/tools.sh index e40e25f..c88cc55 100644 --- a/tools.sh +++ b/tools.sh @@ -1,5 +1,25 @@ #!/bin/sh +if [ "$(which awk)" ]; then + md() { awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk"; } +elif [ "$(which busybox)" ]; then + md() { busybox awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk"; } +else + md() { cat; } +fi + +mdfile(){ + local page="$(PATH "$1")" + + if [ -f "$_DATA/pages/$page/#page.md" ]; then + printf %s\\n "$_DATA/pages/$page/#page.md" + elif [ -f "$_EXEC/pages/$page/#page.md" ]; then + printf %s\\n "$_EXEC/pages/$page/#page.md" + else + return 1 + fi +} + size_human(){ local size="$1" @@ -21,7 +41,7 @@ size_human(){ } page_glob(){ - local pattern="$1" IFS='' + local pattern="${1%/}/" IFS='' local glob page pagedir case $pattern in