#!/bin/sh

MD_FILE='pages/listing.md'
TITLE="All the things!"

DIRECTORIES="downloads
pics
script
volatile"

if [ "$SCRIPT_PATH" = '' ]
then
  export SCRIPT_PATH=`realpath "$0"`
fi

# --- Markdown listing ---
FRONT_MATTER="---
layout: default
---

# Everything!
"

echo "$FRONT_MATTER" > "$MD_FILE"
echo '<!-- File autogenerated by make-listing.sh -->' >> "$MD_FILE"
for d in $DIRECTORIES
do
  echo "Making listing for $d"
  echo "" >> "$MD_FILE"
  echo "<!-- Table break -->" >> "$MD_FILE"
  echo "" >> "$MD_FILE"
  echo "| $d |" >> "$MD_FILE"
  echo "|----|" >> "$MD_FILE"
  for f in `find "$d" -type f | sort`
  do
    FILENAME=`echo "$f" | sed "s|$d/||"`
    f=`echo "$f" | sed 's/\.md$/.html/' ` #<-- .md files get processed into html
    echo "| [$FILENAME]({{ \"$f\" | absolute_url }}) |" >> "$MD_FILE"
  done
done
