#!/bin/sh
set -eu

mkdir -p public

PROJECT_UC="$1"
PROJECT="$2"

RELEASES_LIST="$(mktemp)"
for version in $(git tag); do
  echo "- version [$version](https://git.euandreh.xyz/$PROJECT/snapshot/$PROJECT-$version.tar.gz), released in $(git log -1 --format=%cd --date=short "$version")" >> "$RELEASES_LIST"
done

RELEASES="$(mktemp)"
if [ -s "$RELEASES_LIST" ]; then
  printf '\n# Releases\n\n' >> "$RELEASES"
  cat "$RELEASES_LIST" >> "$RELEASES"
fi

cat README.md "$RELEASES" | \
  pandoc --toc                                   \
         --highlight-style pygments              \
         --toc-depth=2                           \
         -s                                      \
         --metadata title="$PROJECT_UC - README" \
         --metadata lang=en                      \
         -r markdown                             \
         -w html                                 \
         > public/index.html
