From e2413adfaa472beb373299f95423dde10bcef718 Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Fri, 30 Apr 2021 21:55:13 +0100 Subject: [PATCH] initial commit --- Makefile | 8 ++++++ gen_notes.sh | 60 +++++++++++++++++++++++++++++++++++++++++ styles.css | 50 ++++++++++++++++++++++++++++++++++ templates/article.html | 11 ++++++++ templates/index.html | 10 +++++++ templates/listitem.html | 1 + 6 files changed, 140 insertions(+) create mode 100644 Makefile create mode 100755 gen_notes.sh create mode 100644 styles.css create mode 100644 templates/article.html create mode 100644 templates/index.html create mode 100644 templates/listitem.html diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..35232da --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +install: + cp gen_notes.sh /usr/local/bin + mkdir -p /opt/gen_notes + cp -r templates /opt/gen_notes + cp styles.css /opt/gen_notes + +clean: + rm -rf /usr/local/bin/gen_notes.sh /opt/gen_notes diff --git a/gen_notes.sh b/gen_notes.sh new file mode 100755 index 0000000..541b00f --- /dev/null +++ b/gen_notes.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +[[ -z "$1" ]] && echo "USAGE: $0 NOTES_DIRECTORY" && exit 0 + +function _render { + echo "rendering $1" + pandoc\ + --toc\ + --standalone\ + -t html\ + --template /opt/gen_notes/templates/article.html\ + -o "$(dirname "$1")/index.html"\ + "$1"\ + --mathjax +} + +function _renderindex { + echo "rendering $1" + pandoc\ + -t html\ + --template /opt/gen_notes/templates/index.html\ + -o index.html\ + "$1" +} + +function _addtolist { + echo "adding $1 to list of notes" + pandoc\ + -t html\ + -V "filepath=$(dirname "$1")"\ + --template /opt/gen_notes/templates/listitem.html\ + "$1"\ + >> index.md +} + +export -f _render +export -f _addtolist + +#render each markdown file + +for var in "$@" +do + find "$var" -name '*.md' -exec bash -c "_render '{}'" \; +done + +# create an intermediate markdown file of links to each article +echo "--- +title: alv's notes +---" > index.md + +for var in "$@" +do + echo "

$var notes

" >> index.md + find "$var" -name '*.md' -exec bash -c "_addtolist '{}'" \; +done + +_renderindex index.md + +echo "copying styles.css to current directory" +cp /opt/gen_notes/styles.css . diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..01d5b7e --- /dev/null +++ b/styles.css @@ -0,0 +1,50 @@ +body { + font-family: "Open Sans", sans-serif; + color: #454545; + font-size: 16px; + margin: 2em auto; + max-width: 800px; + padding: 1em; + line-height: 1.4; + text-align: justify; + background-color: #fefefe; +} + +a { color: #07a; } +a:visited { color: #941352; } + +img[class="centered"] { + margin: 0 auto; + display: block; +} + +table { + border-collapse: collapse; + margin: 1em auto; +} +th, td { + padding: 1em; + border: 1px solid #454545; + margin: 0; +} + + +pre { + background-color: #d9d9d9 ; + color: #000; + padding: 1em; +} + +details { + padding: 1em 0 1em 0; +} + +li { + margin-bottom: 1em; +} + +img { + margin: 0 auto; + display: block; + max-width: 100%; +} diff --git a/templates/article.html b/templates/article.html new file mode 100644 index 0000000..543b661 --- /dev/null +++ b/templates/article.html @@ -0,0 +1,11 @@ + + + + + + + +$title$ + + + $body$ diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..d233a28 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,10 @@ + + + + + +$title$ + + +$body$ + diff --git a/templates/listitem.html b/templates/listitem.html new file mode 100644 index 0000000..1937fe8 --- /dev/null +++ b/templates/listitem.html @@ -0,0 +1 @@ +
  • $title$