#!/bin/bash

# Converts the markdown posts to html files
# Cleanup html directory
rm -f html/*

# Iterate over the files
inputFiles=`ls markdown`
for file in $inputFiles
do
    # Get the title (without the suffix)
    title=`basename --suffix=".md" $file`
    titleWithoutDate=`echo "$title" | sed -E "s/^[0-9.]+_(.*)$/\1/"`

    # Make links absolute
    content=`cat markdown/$file`
    absoluteContent=`echo "$content" | \
        sed "s/](\.\.\//](https:\/\/timber.codeberg.page\/nomadActivist\//g" | \
        sed "s/](\.\//](https:\/\/timber.codeberg.page\/nomadActivist\/html\//g"`
    # Convert file to html
    echo "$absoluteContent" | \
        pandoc --css=../solarized_dark.css --to=html5 --standalone -o "html/$title.html" -V pagetitle="$titleWithoutDate"
done
