]> Nishi Git Mirror - aya.git/commitdiff
Add list plugin to contrib
authorJames Mills <1290234+prologic@users.noreply.github.com>
Thu, 30 Mar 2023 12:53:03 +0000 (22:53 +1000)
committerJames Mills <1290234+prologic@users.noreply.github.com>
Thu, 30 Mar 2023 12:53:03 +0000 (22:53 +1000)
contrib/plugins/list [new file with mode: 0755]

diff --git a/contrib/plugins/list b/contrib/plugins/list
new file mode 100755 (executable)
index 0000000..ace7f3d
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+if [ ! $# = 1 ]; then
+    printf >&2 "Usage: %s <path> [ext]\n" "$(basename "$0")"
+    exit 0
+fi
+
+p="$1"
+t="${2:-md}"
+
+if [ ! -d "$p" ]; then
+    printf >&2 "error: path %s not found\n" "$p"
+    exit 1
+fi
+
+find "$p" -type f -name "*.$t" | while read -r file; do
+    name="${file#"$p"}"
+    name="${name#"/"}"
+    name="${name%.*}"
+
+    title="$(zs vars "$file" title)"
+    if [ -z "$title" ]; then
+        title="$name"
+    fi
+
+    echo "- [$title](${p}/${name}.html)"
+done