#!/bin/bash source_to_target() { sed -E -e 's:\.\./src/:\./:' -e 's/.md$/.html/'; } escape_newlines() { tr -d "\\n"; } shopt -s globstar rm -rf dist/ mkdir dist&&cd dist cp ../style.css . for file in $(du -a ../src/ | cut -f2 | grep -E '.md$'); do target="$(echo $file | source_to_target)" content="$(pandoc --from markdown+emoji --wrap=none -i $file | sed -e 's/[]\/$*.^[]/\\&/g' | escape_newlines )" # To escape the string for sed later on prefix=$(realpath --relative-to $(dirname $target) .) sidebar=$(for x in ../src/**/*.md; do echo "
  • $(realpath --relative-to ../src/ $x | sed -e 's/.md$//')
  • " | sed -e 's/[]\/$*.^[]/\\&/g' | escape_newlines; done) mkdir -p $(dirname $target) cat ../template.tpl | sed -e "s/{CONTENT}/$content/" -e "s:{PREFIX}:$prefix:" -e "s/{SIDEBAR}/$sidebar/" > $target done