aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-03-27 08:58:40 -0300
committerEuAndreh <eu@euandre.org>2023-03-27 08:58:40 -0300
commit07ef3c2a2cce2f055a1174a8f49c4895dc9f6b30 (patch)
tree7ef129bd27807abcd750bd6a8455e8adf02d8657
parentreconfigure.sh: Fix permissions of rsynced files (diff)
downloadserver-07ef3c2a2cce2f055a1174a8f49c4895dc9f6b30.tar.gz
server-07ef3c2a2cce2f055a1174a8f49c4895dc9f6b30.tar.xz
Add minimum support for generating actual HTML files in public/
Notes
See CI logs with: git notes --ref=refs/notes/ci-logs show 07ef3c2a2cce2f055a1174a8f49c4895dc9f6b30 git notes --ref=refs/notes/ci-data show 07ef3c2a2cce2f055a1174a8f49c4895dc9f6b30 Exit status: 1 Duration: 12
-rw-r--r--Makefile23
-rw-r--r--README.md0
-rw-r--r--doc/favicon.svg62
-rwxr-xr-xdoc/md2html.sh97
-rw-r--r--src/development/lib.sh33
5 files changed, 212 insertions, 3 deletions
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
--- /dev/null
+++ b/README.md
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 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16">
+ <path d="M 0 8 L 1 8 L 1 9 L 0 9 L 0 8 Z" />
+ <path d="M 0 13 L 1 13 L 1 14 L 0 14 L 0 13 Z" />
+ <path d="M 1 8 L 2 8 L 2 9 L 1 9 L 1 8 Z" />
+ <path d="M 1 13 L 2 13 L 2 14 L 1 14 L 1 13 Z" />
+ <path d="M 2 8 L 3 8 L 3 9 L 2 9 L 2 8 Z" />
+ <path d="M 2 13 L 3 13 L 3 14 L 2 14 L 2 13 Z" />
+ <path d="M 3 8 L 4 8 L 4 9 L 3 9 L 3 8 Z" />
+ <path d="M 3 13 L 4 13 L 4 14 L 3 14 L 3 13 Z" />
+ <path d="M 4 7 L 5 7 L 5 8 L 4 8 L 4 7 Z" />
+ <path d="M 4 8 L 5 8 L 5 9 L 4 9 L 4 8 Z" />
+ <path d="M 4 13 L 5 13 L 5 14 L 4 14 L 4 13 Z" />
+ <path d="M 5 6 L 6 6 L 6 7 L 5 7 L 5 6 Z" />
+ <path d="M 5 7 L 6 7 L 6 8 L 5 8 L 5 7 Z" />
+ <path d="M 5 13 L 6 13 L 6 14 L 5 14 L 5 13 Z" />
+ <path d="M 6 5 L 7 5 L 7 6 L 6 6 L 6 5 Z" />
+ <path d="M 6 6 L 7 6 L 7 7 L 6 7 L 6 6 Z" />
+ <path d="M 6 14 L 7 14 L 7 15 L 6 15 L 6 14 Z" />
+ <path d="M 7 1 L 8 1 L 8 2 L 7 2 L 7 1 Z" />
+ <path d="M 7 14 L 8 14 L 8 15 L 7 15 L 7 14 Z" />
+ <path d="M 7 15 L 8 15 L 8 16 L 7 16 L 7 15 Z" />
+ <path d="M 7 2 L 8 2 L 8 3 L 7 3 L 7 2 Z" />
+ <path d="M 7 3 L 8 3 L 8 4 L 7 4 L 7 3 Z" />
+ <path d="M 7 4 L 8 4 L 8 5 L 7 5 L 7 4 Z" />
+ <path d="M 7 5 L 8 5 L 8 6 L 7 6 L 7 5 Z" />
+ <path d="M 8 1 L 9 1 L 9 2 L 8 2 L 8 1 Z" />
+ <path d="M 8 15 L 9 15 L 9 16 L 8 16 L 8 15 Z" />
+ <path d="M 9 1 L 10 1 L 10 2 L 9 2 L 9 1 Z" />
+ <path d="M 9 2 L 10 2 L 10 3 L 9 3 L 9 2 Z" />
+ <path d="M 9 6 L 10 6 L 10 7 L 9 7 L 9 6 Z" />
+ <path d="M 9 15 L 10 15 L 10 16 L 9 16 L 9 15 Z" />
+ <path d="M 10 2 L 11 2 L 11 3 L 10 3 L 10 2 Z" />
+ <path d="M 10 3 L 11 3 L 11 4 L 10 4 L 10 3 Z" />
+ <path d="M 10 4 L 11 4 L 11 5 L 10 5 L 10 4 Z" />
+ <path d="M 10 5 L 11 5 L 11 6 L 10 6 L 10 5 Z" />
+ <path d="M 10 6 L 11 6 L 11 7 L 10 7 L 10 6 Z" />
+ <path d="M 11 6 L 12 6 L 12 7 L 11 7 L 11 6 Z" />
+ <path d="M 11 8 L 12 8 L 12 9 L 11 9 L 11 8 Z" />
+ <path d="M 10 15 L 11 15 L 11 16 L 10 16 L 10 15 Z" />
+ <path d="M 11 10 L 12 10 L 12 11 L 11 11 L 11 10 Z" />
+ <path d="M 11 12 L 12 12 L 12 13 L 11 13 L 11 12 Z" />
+ <path d="M 11 14 L 12 14 L 12 15 L 11 15 L 11 14 Z" />
+ <path d="M 11 15 L 12 15 L 12 16 L 11 16 L 11 15 Z" />
+ <path d="M 12 6 L 13 6 L 13 7 L 12 7 L 12 6 Z" />
+ <path d="M 12 8 L 13 8 L 13 9 L 12 9 L 12 8 Z" />
+ <path d="M 12 10 L 13 10 L 13 11 L 12 11 L 12 10 Z" />
+ <path d="M 12 12 L 13 12 L 13 13 L 12 13 L 12 12 Z" />
+ <path d="M 12 14 L 13 14 L 13 15 L 12 15 L 12 14 Z" />
+ <path d="M 13 6 L 14 6 L 14 7 L 13 7 L 13 6 Z" />
+ <path d="M 13 8 L 14 8 L 14 9 L 13 9 L 13 8 Z" />
+ <path d="M 13 10 L 14 10 L 14 11 L 13 11 L 13 10 Z" />
+ <path d="M 13 12 L 14 12 L 14 13 L 13 13 L 13 12 Z" />
+ <path d="M 13 13 L 14 13 L 14 14 L 13 14 L 13 13 Z" />
+ <path d="M 13 14 L 14 14 L 14 15 L 13 15 L 13 14 Z" />
+ <path d="M 14 7 L 15 7 L 15 8 L 14 8 L 14 7 Z" />
+ <path d="M 14 8 L 15 8 L 15 9 L 14 9 L 14 8 Z" />
+ <path d="M 14 9 L 15 9 L 15 10 L 14 10 L 14 9 Z" />
+ <path d="M 14 10 L 15 10 L 15 11 L 14 11 L 14 10 Z" />
+ <path d="M 14 11 L 15 11 L 15 12 L 14 12 L 14 11 Z" />
+ <path d="M 14 12 L 15 12 L 15 13 L 14 13 L 14 12 Z" />
+</svg>
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'
+ <link rel="icon" href="favicon.svg" type="image/svg+xml" />
+ <link rel="stylesheet" href="style.css" type="text/css" />
+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"
+}