#!/bin/bash CSS=$(cat ./styles.css) HTML_BEGIN="
" HTML_END=" " cd "$(dirname "$0")" find . -type f -name "*.md" -print0 | while IFS= read -r -d '' mdfile; do dir=$(dirname "$mdfile") base=$(basename "$mdfile" .md) if [[ "$base" == "README" ]]; then out_base="index" else out_base="$base" fi html_raw="$dir/$out_base.html.raw" html_final="$dir/$out_base.html" pandoc "$mdfile" -t html -o "$html_raw" { echo "$HTML_BEGIN" sed -E 's/href="(\.\/[^.]+)"/href="\1\/"/g' "$html_raw" | \ python3 -c "import sys, re; print(re.sub(r'href=\"([^\"]+)\"', lambda m: 'href=\"' + m.group(1).replace('?', '%3F').replace('!', '%21') + '\"', sys.stdin.read()), end='')" echo "$HTML_END" } > "$html_final" echo "Converted: $mdfile" done