www

https://garbash.com/~alex/
git clone git://git.garbash.com/alex/www
Log | Files | Refs | README | LICENSE

commit 34be727f3b7381a06ebde31563dbcea05d39e8a7
parent b0afd529b3fa87479e8a5795f3ea9fa42ba3e815
Author: alex <alex@garbash.com>
Date:   Sun, 24 Oct 2021 23:36:22 -0400

build: Add new buildpage tool with custom <title> support

Had to hack a bit of an ugly frontmatter parser! Of course, this thing
isn't CLOSE to parsing YAML but it's a little more explainable than
custom comments in the markdown that have syntactic meaning.

Diffstat:
M.gitignore | 1-
MMakefile | 3+--
Abin/buildpage | 33+++++++++++++++++++++++++++++++++
Mindex.md | 4++++
Mroot-index.md | 4++++
Dtemplate.html | 10----------
6 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,2 +1 @@ *.html -!template.html diff --git a/Makefile b/Makefile @@ -7,7 +7,6 @@ clean: .SUFFIXES: .md .html .md.html: - (sed '/<body>/q' template.html; cmark < $<; printf "</body>\n</html>\n") > $@ - + ./bin/buildpage $< > $@ .PHONY: all clean diff --git a/bin/buildpage b/bin/buildpage @@ -0,0 +1,33 @@ +#!/bin/sh +# buildpage -- small markdown wrapper with frontmatter <title> support +set -e +die() { + echo "$*" 1>&2 + exit 1 +} + +[ -z "$1" ] && die "usage: downtown FILE" + +# Print the header +cat <<EOM +<!DOCTYPE html> +<html lang="en"> +<head> +<meta charset="utf-8"/> +<meta name="viewport" content="width=device-width,initial-scale=1"> +EOM + +# Print the title, if we find it in the frontmatter +if [ "$(head -n1 "$1")" = "---" ]; then + title="$(tail +2 "$1" | sed '/^---$/q' | grep '^title:' | sed 's/title: *//')" + [ -n "$title" ] && printf "<title>$title</title>\n" + start=$(awk '/^---$/ { c++; if (c == 2) { printf "%d\n", NR + 1; exit } }' "$1") +else + start=1 +fi +printf "</head>\n<body>\n" + +# Render the markdown starting from the end of the frontmatter! +tail +$start "$1" | cmark --unsafe + +printf "</body>\n</html>\n" diff --git a/index.md b/index.md @@ -1,3 +1,7 @@ +--- +title: ~alex +--- + ~alex's page ============ diff --git a/root-index.md b/root-index.md @@ -1,3 +1,7 @@ +--- +title: garbash.com +--- + Welcome ======= ``` diff --git a/template.html b/template.html @@ -1,10 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> -<meta charset="utf-8"/> -<meta name="viewport" content="width=device-width,initial-scale=1"> -</head> -<body> - <!-- TEMPLATE --> -</body> -</html>