#!/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 -e "\033[0;32m[COMPILE ]\033[0m $1 -> $TARGET" pandoc "$1" \ -f markdown \ -t html5 \ --template templates/base.html \ -o "$TARGET" \ --metadata-file metadata/metadata.json else echo -e "\033[0;32m[COPY ]\033[0m $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 -e "\033[0;31m[ERROR ]\033[0m \"single\" operation requires file argument" else handle "$2" fi elif [ "$1" = "delete" ]; then if [ -z "$2" ]; then echo -e "\033[0;31m[ERROR ]\033[0m \"delete\" operation requires file argument" else TARGET=$(target "$2") echo -e "\033[0;32m[DELETE ]\033[0m $2 -> $TARGET" rm -rf $TARGET fi else echo -e "\033[0;31m[ERROR ]\033[0m Unknown operation: \"$1\"" fi