#!/bin/sh # web/site-page.sh -- one page of the Hugo site from a document in the tree. # # Usage: sh web/site-page.sh README.md 40 README https:///blob/main # # Prints the page on standard output: a front-matter block, then the document # with its logo block, author line, `Contents` list and its own `# ` heading # removed -- the site has a logo in the header, a contents list in the sidebar # and the title in the front matter. Links are rewritten on the way: a link # from one document into the other becomes a link to that other page, and a # link to any other file in the tree becomes a link to that file on GitHub, # which is where it can be read. # # This used to be an inline awk program in the Makefile, where make expanded # the `$` in `$/` and `$0` as one-letter variables and handed awk a program # with a syntax error, so the README page was never written and nothing said # so. set -eu if [ $# -ne 4 ]; then echo "usage: $0 FILE WEIGHT TITLE REPOURL" >&2 exit 2 fi src=$1 weight=$2 title=$3 repo=$4 [ -f "$src" ] || { echo "$0: $src: no such file" >&2; exit 2; } # The front matter names the document in the tree, not the path it was read by. base=${src##*/} printf '%s\n' '---' "title: $title" "weight: $weight" "source: $base" '---' '' awk ' /^

Sean Kurtz<\/p>$/ { next } /^

$/ { logo = 1; next } logo { if ($0 == "

") { logo = 0 }; next } /^## Contents$/ { toc = 1; next } toc && /^## / { toc = 0 } toc { next } !h1 && /^# / { h1 = 1; next } { print } ' "$src" | sed -e 's|](DESIGN.md#|](../design/#|g' \ -e 's|](README.md#|](../readme/#|g' \ -e 's|](DESIGN.md)|](../design/)|g' \ -e 's|](README.md)|](../readme/)|g' \ -e "s|](\([A-Za-z][A-Za-z0-9_/.-]*\.md\)#|]($repo/\1#|g" \ -e "s|](\([A-Za-z][A-Za-z0-9_/.-]*\.md\))|]($repo/\1)|g" \ -e "s|](LICENSE)|]($repo/LICENSE)|g"