From 41ea1757508169957d0ff91ccd94ffea5cc676be Mon Sep 17 00:00:00 2001 From: Mohit Agarwal Date: Fri, 14 Mar 2025 18:37:19 +0000 Subject: Initial commit. --- make | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100755 make (limited to 'make') diff --git a/make b/make new file mode 100755 index 0000000..8125bd4 --- /dev/null +++ b/make @@ -0,0 +1,125 @@ +#!/usr/bin/env bash +TITLE="Unorthodox Monolgues" +AUTHOR="Abigail Kelley" +EMAIL="UNMONO@MOHIT.UK" + +OUTFILE="unmono" +LANG="en_GB" + +# Convert a markdown file to HTML and store it in the OUTFILE +md2html() { + local file=$1 + + echo "Building $file..." >&2 + + filename_html=$OUTFILE/${file/%.md/.html} + filename_pdf=$OUTFILE/${file/%.md/.pdf} + + local args=( + "--email-obfuscation=references" + "--from=markdown+emoji" + "--metadata=lang:$LANG" + "--shift-heading-level-by=-1" + "--toc-depth=4" + ) + + local args_html=( + "--css=static/style.css" + "--css=static/document.css" + "--include-before-body=header.html" + "--include-in-header=headerlinks.html" + "--table-of-contents" + ) + + local args_pdf=( + "--pdf-engine=xelatex" + ) + + # args+=("--citeproc") # Citations + # args+=("--mathjax") # Mathematical rendering + + # args+=("--include-after-body=$goatcounter") + # args+=("--include-in-header=$favicon") + + if [[ $file == ????-??-??-* ]]; then + args+=("--metadata=date:$(fmtdate ${file:0:10})") + fi + + if [[ $file == 'index.md' ]]; then + args+=("--metadata=pagetitle:$TITLE") + fi + + if [[ $file -nt $filename_html ]]; then + pandoc "${args[@]}" "${args_html[@]}" -t html \ + --output=$OUTFILE/${file/%.md/.html} "$file" || echo "error while converting $file"; + pandoc "${args[@]}" "${args_pdf[@]}" -t pdf \ + --output=$OUTFILE/${file/%.md/.pdf} "$file" || echo "error while converting $file"; + fi +} + +extracttitle() { + local file=$1 + sed -n '/^# /{s///p;q}' "$file" +} + +extractauthor() { + grep "author" $f | sed 1q | cut -d":" -f 2 +} + +fmtdate() { + date --date="$1" "+%d %b %Y" +} + +# Build all pages +build() { + + echo "./make --------------------------------------------------" + echo " Blog builder" + echo " Written by Mohit Agarwal" + echo " FOR INTERNAL USE ONLY" + echo "---------------------------------------------------------" + + echo "" + echo "TITLE $TITLE" + + + # Build index file and convert posts + echo "" + echo "Building index.html and converting posts" + { + echo '' + echo '' + echo '' + echo '' + echo '' + echo " $TITLE " + echo '' + echo '' + echo '' + echo "

$TITLE

" + local f + for f in ????-??-??-*.md; do + echo '' + echo "$(fmtdate ${f:0:10}) - $(extractauthor "$f")" + echo "

$(extracttitle "$f")

" + echo '
' + md2html "$f" + done | tac + } > index.html + + ./feed.sh + + echo "" + echo "COPYING FILES" + cp -v index.html $OUTFILE/ + cp -vr static $OUTFILE/ + cp -vr images $OUTFILE/ + cp -vr feed.xml $OUTFILE/ + + echo "" + echo "BLOG PUBLISHED" + echo "---------------------------------------------------------" + echo "---------------------------------------------------------" +} + +build -- cgit v1.2.3