File: make-index.sh

package info (click to toggle)
moarvm 2018.12%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,196 kB
  • sloc: ansic: 223,172; perl: 7,638; sh: 4,452; makefile: 1,089; python: 568; asm: 8
file content (24 lines) | stat: -rwxr-xr-x 705 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
# Adapted from script by 'Peter van der Does' on website stackoverflow.com
# CC-by-SA
# https://stackoverflow.com/questions/21395159/shell-script-to-create-a-static-html-directory-listing
root="."
echo "<ul>"
DEPTH=1
files="$(find $root -maxdepth $DEPTH)"
for file in $files; do
  parentpath="${file#*/}"
  parent="${parentpath%/*}"
  filename="${file##*/}"
  if [[ -z $oldparent ]]; then
    echo "  <li> $parent </li>" && oldparent="$parent"
    echo "  <ul>"
  elif [[ $oldparent != $parent ]]; then
    echo "  </ul>"
    echo "  <li> $parent </li>" && oldparent="$parent"
    echo "  <ul>"
  fi
  echo "    <li><a href=\"$parentpath\">$filename</a></li>"
done
echo "  </ul>"
echo "</ul>"