]> git.plutz.net Git - shellwiki/commitdiff
move functions to tools
authorPaul Hänsch <paul@plutz.net>
Tue, 17 May 2022 21:25:22 +0000 (23:25 +0200)
committerPaul Hänsch <paul@plutz.net>
Tue, 17 May 2022 21:25:22 +0000 (23:25 +0200)
index.cgi
tools.sh

index 0c7e914062c3d99c38420e106c32b6a29c3dc59d..8975ccaa0cc1b2b6e76d4f8d13474648ca0d1311 100755 (executable)
--- 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
index e40e25f4be075bb97589fc6415e09c3c2dc5b025..c88cc55c12bfdeaedf482d4dddcfed51941e7281 100644 (file)
--- 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