aboutsummaryrefslogtreecommitdiff
path: root/generate-index-html.sh
diff options
context:
space:
mode:
Diffstat (limited to 'generate-index-html.sh')
-rwxr-xr-xgenerate-index-html.sh23
1 files changed, 23 insertions, 0 deletions
diff --git a/generate-index-html.sh b/generate-index-html.sh
new file mode 100755
index 0000000..bf6fd3e
--- /dev/null
+++ b/generate-index-html.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+# Generates an index.html with support for rendering a README.md if present.
+# With -R an entire directory hierarchy can be converted.
+# generate-index-html [-R] <dir>
+set -e
+
+if [ "x$1" = "x-R" ]; then
+ exec find "$2" -type d -exec "$0" '{}' ';'
+fi
+
+cd "$1"
+
+(echo '<html><head><meta charset="utf-8"><title>Directory listing</title></head><body>'
+ if [ -f README.md ]; then
+ lowdown -thtml --html-no-skiphtml --html-no-escapehtml README.md
+ echo '<hr>'
+ fi
+ echo -n '<pre>'
+ # Assumes a BSD ls.
+ ls -Flha | grep -Ev ' (\./|index\.html|README\.md|\.git/|\.gitignore)$' | \
+ cut -w -f 5- | sed -E 's|^([^\t]+\t+)([^ ]+ +)([^ ]+ +)([^ ]+ +)(.*[^*])\*?$|\1\2\3\4<a href="\5" target="_self">\5</a>|'
+ echo '</pre></body></html>'
+) >index.html