#!/bin/bash target () { if [ "${1#*.}" = "md" ]; then echo "output/$(echo "${1%.md}.html" | cut -sd / -f 2-)" else echo "output/$(echo "$1" | cut -sd / -f 2-)" fi } handle () { TARGET=$(target "$1") mkdir -p $(dirname "$TARGET") if [ "${1#*.}" = "md" ]; then echo "[COMPILE] $1 -> $TARGET" pandoc "$1" \ -f markdown \ -t html5 \ --template templates/base.html \ -o "$TARGET" \ --metadata-file metadata/metadata.json else echo "[COPY ] $1 -> $TARGET" cp "$1" "$TARGET" fi } if [ -z "$1" ]; then find content/ \ -type f \ | while read FILE do handle "$FILE" done elif [ "$1" = "md" ]; then find content/ \ -type f \ -name "*.md" \ | while read FILE do handle "$FILE" done elif [ "$1" = "single" ]; then if [ -z "$2" ]; then echo "[ERROR ] \"single\" operation requires file argument" else handle "$2" fi elif [ "$1" = "delete" ]; then if [ -z "$2" ]; then echo "[ERROR ] \"delete\" operation requires file argument" else TARGET=$(target "$2") echo "[DELETE ] $2 -> $TARGET" rm -rf $TARGET fi else echo "[ERROR ] Unknown operation: \"$1\"" fi