Skip to content
Snippets Groups Projects
pages.sh 1.26 KiB
Newer Older
x2004933's avatar
x2004933 committed
#!/usr/bin/env bash
set -euo pipefail

site_dir="site"
main_dir=""
pages_dir="public"
template="index.html"
links=""

x2004933's avatar
x2004933 committed
mkdir -p "${pages_dir}"

# Set the diff tool
git config diff.pandoc.textconv 'pandoc -t gfm'
x2004933's avatar
x2004933 committed

# Get the relevant commits from the log
commits=$(git log --pretty=oneline | grep "Update at" | cut -d' ' -f1)

# Create the website for the relevant commit
for c in $commits
do
    # Checkout the relevant commit
x2004933's avatar
x2004933 committed
    git checkout "$c" -- "${site_dir}"
x2004933's avatar
x2004933 committed

    # Get the date of the commit
    date=$(git show -s --format=%ai "$c")

x2004933's avatar
x2004933 committed
    # Show the latest commit
    git diff "$c~1" "$c" -- "${site_dir}" > "${pages_dir}/${c}.diff.txt"

    # Check if commit is empty
    if [[ -s "${pages_dir}/${c}.diff.txt" ]]
    then
        diff="<a href=\"${c}.diff.txt\">diff</a>"
    else
        diff="no changes"
    fi

x2004933's avatar
x2004933 committed
    # Copy the state of the site to the pages dir
    cp -a "${site_dir}" "${pages_dir}/${date}"

    # Add a link to the index
x2004933's avatar
x2004933 committed
    links="${links}<li><a href=\"${date}/${main_dir}\">${date}</a> (${diff})</li>"
x2004933's avatar
x2004933 committed

    # Create a 'latest' symlink for the latest commit
    [ ! -e "${pages_dir}/latest" ] && ln -s "${date}" "${pages_dir}/latest"
done
x2004933's avatar
x2004933 committed
git checkout master -- site/
x2004933's avatar
x2004933 committed

# Create index file
sed "s|{{body}}|${links}|g" "${template}" > "${pages_dir}/index.html"