blob: bf6fd3ecbac91324b4fe1e7ab39d29078f306b75 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
|