#!/bin/sh

ROOT=${1:-"$PWD"}

cat <<EOF
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<title>Listing</title>
</head>
<body>
EOF

i=0
echo "<ul>"
for filepath in $ROOT; do
  find "$filepath" -maxdepth 1 -mindepth 1 -type d | sort | while read i; do
    file=`basename "$i"`
    echo "    <li><a href=\"$file/\">$file/</a></li>"
  done
  find "$filepath" -maxdepth 1 -mindepth 1 -type f | grep -v 'index.html$' | sort | while read i; do
    file=`basename "$i"`
    echo "    <li><a href=\"$file\">$file</a></li>"
  done
done
echo "</ul>"

cat <<EOF
<script src="/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
</body>
</html>
EOF
