#!/usr/bin/env bash # # SPDX-License-Identifier: MIT # gitlab-ci looks here [[ ! -d ./public ]] && mkdir ./public # copy our CSS - _CSS="mdhtml.css" cp "./style/${_CSS}" ./public/ # icon _FAV="favicon.ico" cp "./style/${_FAV}" ./public/ # ./src/foo.md -> ./public/foo.html for file in ./src/*.md; do _FILE="${file##*/}" _HTML="./public/${_FILE%.*}.html" echo "Processing $file to $_HTML" # metadata for pandoc _TITLE=$(grep -m1 "^# " "$file" | sed -r 's/# //') # [foo](foo.md) -> [foo](foo.html) # sed -i -r 's/(\[.*?\])\((.*?)\.md\)/\1(\2.html)/' "$file" # sed does not support non-greedy (.*?) like perl, we have to hack it sed -i -r \ -e ':loop' \ -e 's/(\[.*\])\((.*)\.md\)/\1(\2.html)/g' \ -e 't loop' $file pandoc -s \ -f gfm+gfm_auto_identifiers-ascii_identifiers \ -t html \ --template="./style/pandoc_html.tpl" \ --include-in-header="./style/header_include.html" \ --include-before-body="./style/body_before.html" \ --include-after-body="./style/body_after.html" \ --metadata pagetitle="$_TITLE" \ --css="${_CSS}" \ -o "${_HTML}" "$file" done