diff options
author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-10-06 01:06:30 +0300 |
---|---|---|
committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-10-06 01:06:30 +0300 |
commit | 94c49df7dd27629d6a28f50028db483085907c96 (patch) | |
tree | aa50cb59510db7a86c435aeccffaac14b194e745 /generate-index-html.sh | |
parent | ad9e7cd5117c965222aae708f660e56d537914fc (diff) | |
download | snippets-94c49df7dd27629d6a28f50028db483085907c96.tar.gz |
added scripts used for administration of fmsbw.de
Diffstat (limited to 'generate-index-html.sh')
-rwxr-xr-x | generate-index-html.sh | 23 |
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 |