From 07ef3c2a2cce2f055a1174a8f49c4895dc9f6b30 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Mon, 27 Mar 2023 08:58:40 -0300 Subject: Add minimum support for generating actual HTML files in public/ --- Makefile | 23 ++++++++++-- README.md | 0 doc/favicon.svg | 62 ++++++++++++++++++++++++++++++++ doc/md2html.sh | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/development/lib.sh | 33 +++++++++++++++++ 5 files changed, 212 insertions(+), 3 deletions(-) create mode 100644 README.md create mode 100644 doc/favicon.svg create mode 100755 doc/md2html.sh create mode 100644 src/development/lib.sh diff --git a/Makefile b/Makefile index 7cb462e..708b1a0 100644 --- a/Makefile +++ b/Makefile @@ -47,9 +47,26 @@ clean: public/ src/secrets/*.txt packages system \ -public: - mkdir -p public - echo xablau > public/index.html +public/favicon.svg: + mkdir -p $(@D) + cp doc/favicon.svg $@ + +public/style.css: + mkdir -p $(@D) + td -S > $@ + +html-deps = \ + public/favicon.svg \ + public/style.css \ + +public/index.html: README.md $(html-deps) + sh doc/md2html.sh -T 'README' < README.md > $@ + +public/TODOs.html: TODOs.md $(html-deps) + td -H | sh doc/md2html.sh -T 'TODOs' > $@ + +public: \ + public/index.html public/TODOs.html prod-secrets.txt.gpg = \ diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/doc/favicon.svg b/doc/favicon.svg new file mode 100644 index 0000000..ce566b2 --- /dev/null +++ b/doc/favicon.svg @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/md2html.sh b/doc/md2html.sh new file mode 100755 index 0000000..b6d04a8 --- /dev/null +++ b/doc/md2html.sh @@ -0,0 +1,97 @@ +#!/bin/sh +set -eu + +. src/development/lib.sh + +usage() { + cat <<-'EOF' + Usage: + md2html.sh -T TITLE [-D TOC_DEPTH] < FILE.md + md2html.sh -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -T TITLE the required title of the generated HTML + document + -D TOC_DEPTH the depth of the generated table of + contents (default: 2) + -h, --help show this message + + + Read markdown text from STDIN and emit HTML to STDOUT. + + + Examples: + + Generate the HTML from markdown using the default: + + $ md2html.sh -T 'Homepage' < index.md > index.html + + + Pick a different TOC depth: + + $ md2html.sh -D3 -T 'TODOs' < TODOs.md > TODOs.html + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +TOC_DEPTH=2 +while getopts 'T:D:h' flag; do + case "$flag" in + T) + TITLE="$OPTARG" + ;; + D) + TOC_DEPTH="$OPTARG" + ;; + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +eval "$(assert_arg "${TITLE:-}" '-T TITLE')" + + +HEAD="$(mkstemp)" +trap 'rm -f "$HEAD"' EXIT + +cat <<-'EOF' + + +EOF + +pandoc \ + -s \ + --toc \ + --toc-depth="$TOC_DEPTH" \ + --metadata lang=pt \ + --metadata title="$TITLE" \ + -H "$HEAD" diff --git a/src/development/lib.sh b/src/development/lib.sh new file mode 100644 index 0000000..e345bd6 --- /dev/null +++ b/src/development/lib.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +assert_arg() { + if [ -z "$1" ]; then + printf 'Missing %s.\n\n' "$2" >&2 + cat <<-'EOF' + usage >&2 + exit 2 + EOF + fi +} + +uuid() { + od -xN20 /dev/urandom | + head -n1 | + awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}' +} + +tmpname() { + printf '%s/uuid-tmpname with spaces.%s' "${TMPDIR:-/tmp}" "$(uuid)" +} + +mkstemp() { + name="$(tmpname)" + touch -- "$name" + printf '%s' "$name" +} + +mkdtemp() { + name="$(tmpname)" + mkdir -- "$name" + printf '%s' "$name" +} -- cgit v1.2.3