diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-27 21:48:42 -0600 |
|---|---|---|
| committer | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-27 21:48:42 -0600 |
| commit | 1cb0581bd9e9ac62cc31f0efa39a70d405f699a9 (patch) | |
| tree | 0338872e584d71a190271efe561de9482eff99ed | |
| parent | 7b2d73a0261035f02cca989b4a67861de934ae3d (diff) | |
| download | zash-1cb0581bd9e9ac62cc31f0efa39a70d405f699a9.tar.gz | |
fix(webdocs): make a script out of the page maker, and test it
make reads a `$` in a recipe as a variable reference, so the awk
program that stripped the logo, the author line and the contents list
arrived without its `$`, the README page came out empty and `make
webdocs` said nothing. The page maker is now web/site-page.sh, which
also names the page after the document rather than after the path the
Makefile happened to pass, and tests/scripts/webdocs.sh checks the
result: front matter, no logo or contents list, links rewritten.
| -rw-r--r-- | Makefile | 48 | ||||
| -rw-r--r-- | tests/scripts/webdocs.exp | 9 | ||||
| -rw-r--r-- | tests/scripts/webdocs.sh | 55 | ||||
| -rw-r--r-- | web/site-page.sh | 52 |
4 files changed, 132 insertions, 32 deletions
@@ -453,23 +453,24 @@ docs: doc webdocs # The website's copy of the documents, for the Hugo site in web/ (see # web/README.md). README.md and DESIGN.md are already markdown, so they are -# copied rather than converted, with a front-matter block in front. The -# logo block and the document's own contents list are dropped: the site has a -# logo in its header and a contents list in the sidebar, and the page title -# comes from the front matter. The specification -# is converted from typst's HTML export by web/spec-md.py, which keeps the -# heading ids the spec cross-references and carries the MathML over; the PDF -# is copied too, and the Doxygen HTML that `doc` wrote is copied to -# web/static/reference. +# copied rather than converted, with a front-matter block in front: +# web/site-page.sh drops the logo block, the author line, the document's own +# contents list and its `# ` heading (the site has a logo in its header, a +# contents list in the sidebar and the title in the front matter) and rewrites +# the links -- one document into the other becomes a link to that page, any +# other file in the tree becomes a link into GitHub. That is a script and not +# an awk program in this recipe because make reads a `$` in a recipe as a +# variable reference: it ate the awk `$/` and `$0`, the page came out empty, +# and nothing noticed. tests/scripts/webdocs.sh checks the result. +# The specification is converted from typst's HTML export by web/spec-md.py, +# which keeps the heading ids the spec cross-references and carries the MathML +# over; the PDF is copied too, and the Doxygen HTML that `doc` wrote is copied +# to web/static/reference. # Nothing is committed: the pages feed `hugo --source web`, and # `make clean` removes them. WEBDOCS is source:weight:title. # # doc is a prerequisite because the source reference is copied from what it # writes; the rest of the target does not need it. -# -# The links are rewritten on the way: a link from one document into the other -# becomes a link to the 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. REPOURL = https://github.com/skurtz97/zash/blob/main WEBDOCS = README:40:README DESIGN:50:Design webdocs: doc @@ -478,26 +479,9 @@ webdocs: doc src=$${d%%:*}; rest=$${d#*:}; \ weight=$${rest%%:*}; title=$${rest#*:}; \ page=$$(echo "$$src" | tr 'A-Z' 'a-z'); \ - { printf '%s\n' '---' "title: $$title" "weight: $$weight" \ - "source: $$src.md" '---' ''; \ - awk '\ - /^<p align="center">Sean Kurtz<\/p>$/ { next }\ - /^<p align="center">$/ { logo = 1; next }\ - logo { if ($0 == "</p>") { logo = 0 }; next }\ - /^## Contents$/ { toc = 1; next }\ - toc && /^## / { toc = 0 }\ - toc { next }\ - !h1 && /^# / { h1 = 1; next }\ - { print }\ - ' $$src.md | \ - 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\)#|]($(REPOURL)/\1#|g' \ - -e 's|](\([A-Za-z][A-Za-z0-9_/.-]*\.md\))|]($(REPOURL)/\1)|g' \ - -e 's|](LICENSE)|]($(REPOURL)/LICENSE)|g'; \ - } > web/content/docs/$$page.md || exit 1; \ + sh web/site-page.sh "$$src.md" "$$weight" "$$title" "$(REPOURL)" \ + > web/content/docs/$$page.md || exit 1; \ + [ -s web/content/docs/$$page.md ] || exit 1; \ echo "web/content/docs/$$page.md"; \ done @if command -v typst >/dev/null 2>&1; then \ diff --git a/tests/scripts/webdocs.exp b/tests/scripts/webdocs.exp new file mode 100644 index 0000000..26a6da2 --- /dev/null +++ b/tests/scripts/webdocs.exp @@ -0,0 +1,9 @@ +README front matter ok +README header, contents and title dropped ok +README links rewritten ok +README links to the DESIGN page ok +DESIGN front matter ok +DESIGN header, contents and title dropped ok +DESIGN links rewritten ok +DESIGN links to the README page ok +[status 0] diff --git a/tests/scripts/webdocs.sh b/tests/scripts/webdocs.sh new file mode 100644 index 0000000..fc4c14e --- /dev/null +++ b/tests/scripts/webdocs.sh @@ -0,0 +1,55 @@ +# Integration: the website's pages are generated from README.md and DESIGN.md +# by web/site-page.sh, and they have to come out whole. +# +# The generator used to be an awk program inside the Makefile. Make reads a +# `$` in a recipe as a variable reference, so it turned the awk `$/` and `$0` +# into nothing, awk exited with a syntax error, the page was written empty and +# nothing said so: the site had no README page and `make webdocs` reported +# success. These checks are the ones that would have caught that. +repo=https://github.com/skurtz97/zash/blob/main +root=$TESTS/.. +mkdir site || exit 1 + +for d in README:40:README DESIGN:50:Design; do + name=${d%%:*}; rest=${d#*:} + weight=${rest%%:*}; title=${rest#*:} + other=DESIGN + [ "$name" = DESIGN ] && other=README + page=site/$name.md + "$TSH" "$root/web/site-page.sh" "$root/$name.md" "$weight" "$title" \ + "$repo" >"$page" || exit 1 + + # Front matter, then a page long enough to be the document. + if [ "$(sed -n 1p "$page")" = "---" ] && + [ "$(sed -n 2p "$page")" = "title: $title" ] && + [ "$(sed -n 3p "$page")" = "weight: $weight" ] && + [ "$(sed -n 4p "$page")" = "source: $name.md" ] && + [ "$(wc -l <"$page")" -gt 100 ]; then + echo "$name front matter ok" + else + echo "$name front matter WRONG" + fi + + # The site has a logo, its own contents list and the title, so the + # document's must be gone. + if grep -q 'align="center"' "$page" || grep -q '^## Contents$' "$page" || + grep -q '^# ' "$page"; then + echo "$name header, contents or title still there WRONG" + else + echo "$name header, contents and title dropped ok" + fi + + # No link may still point at a file in the tree. + if grep -q "](.*\.md" "$page" && ! grep -q "](\.\./" "$page"; then + echo "$name links WRONG" + else + echo "$name links rewritten ok" + fi + + # The other document is a page of the site, not a file on GitHub. + if grep -q "]($repo/$other.md" "$page"; then + echo "$name still links to $other.md on GitHub WRONG" + else + echo "$name links to the $other page ok" + fi +done diff --git a/web/site-page.sh b/web/site-page.sh new file mode 100644 index 0000000..dc08c95 --- /dev/null +++ b/web/site-page.sh @@ -0,0 +1,52 @@ +#!/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://<repo>/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 ' + /^<p align="center">Sean Kurtz<\/p>$/ { next } + /^<p align="center">$/ { logo = 1; next } + logo { if ($0 == "</p>") { 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" |
