wowana.me
website source
commit 1562deebf6b316dd18428ca65fdb92cc6111d8ac parent 27815931001f8f7fd0e4abf8ae10140c0915fcb0 Author: opal hart <opal@wowana.me> Date: Thu, 9 May 2019 19:22:27 +0000 fix makefile and add supplementary scripts Diffstat:
M | Makefile | | | 20 | ++++++++++++++------ |
A | blog.sh | | | 10 | ++++++++++ |
A | postproc.sh | | | 20 | ++++++++++++++++++++ |
3 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile @@ -1,7 +1,8 @@ -PHONY := all check clean debug -SRC := $(wildcard src/*.md src/blog/*.md) +.PHONY := all check clean debug +BLOGSRC := $(wildcard src/blog/*.md) +SRC := $(wildcard src/*.md) $(BLOGSRC) OBJ := $(SRC:%.md=%.part.xht) -FINAL := $(OBJ:src/%.part.xht=out/%.xht) +FINAL := $(OBJ:src/%.part.xht=out/%.xht) out/blog/index.xht all: $(FINAL) @@ -17,8 +18,15 @@ debug: @echo "OBJ := $(OBJ)" @echo "FINAL := $(FINAL)" -src/%.xht.part: src/%.md +src/%.part.xht: src/%.md markdown < $< > $@ -out/%.xht: src/%.xht.part - cat src/header.inc $< src/footer.inc > $@ +out/%.xht: src/%.part.xht src/header.inc src/footer.inc + ./postproc.sh $< > $@ + +out/blog/index.xht: $(BLOGSRC) + ( \ + echo '# blog'; \ + grep -H '^# ' $^ | sed 's@^src/blog/\(.*\).md:# \(.*\)@* [\2](\1.xht)@'; \ + ) | markdown | \ + cat -- src/header.inc - src/footer.inc > $@ diff --git a/blog.sh b/blog.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +file="$(mktemp)" +"$EDITOR" "$file" + +date="$(date +%Y%m%d%H%M.%S)" +sed -i -e"2i <!--[time $date]-->" "$file" + +slug="$(<"$file" head -n1 | iconv -f utf-8 -t ascii | tr -cd '[:alnum:] -' | sed 's/^[ -]*//;s/^.*/\L&/;s/ /-/g')" +mv "$file" "$(dirname $0)/src/blog/$slug.md" diff --git a/postproc.sh b/postproc.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +cat src/header.inc + +filename="$1" +slug="$(basename "$filename" .part.xht)" + +unset iso human datepat +date="$(<"$filename" sed -n '/<!--\[time / {s/.* \(.*\)]-->/\1/; p; q}')" +if test -n "$date"; then + iso="$(date -Iseconds -d$date)" + human="$(date +'%Y %b %d' -d$date)" + datepat="s@<!--\[time.*]-->@<time datetime='$iso' title='$iso'>$human</time>@;" +fi + +<"$filename" sed \ + -e"1i <article class='main' id='$slug'>" \ + -e"$datepat"'$a </article>' + +cat src/footer.inc