make-code-index.sh (1291B)
1 #!/bin/sh 2 # Build /code/index.html: the rendered README as the landing page for the code 3 # browser, wearing stagit's own header so the nav is identical. 4 # 5 # usage: tools/make-code-index.sh <stagit-output-dir> <path/to/README.md> 6 # 7 # Reuses the header stagit already emitted into log.html (title, clone URL, nav) 8 # rather than hand-rolling a second copy that would drift. 9 set -eu 10 11 OUT=$1 12 README=$2 13 IDX="$OUT/index.html" 14 15 command -v cmark-gfm >/dev/null 2>&1 || { 16 echo "make-code-index.sh: cmark-gfm not found" >&2 17 exit 1 18 } 19 20 # Everything up to and including <div id="content">, retitled. 21 sed -n '1,/<div id="content">/p' "$OUT/log.html" \ 22 | sed 's|<title>Log - |<title>|' > "$IDX" 23 24 printf '<div id="readme">\n' >> "$IDX" 25 cmark-gfm --extension table \ 26 --extension strikethrough \ 27 --extension autolink \ 28 --extension tagfilter \ 29 "$README" >> "$IDX" 30 printf '</div>\n<hr/>\n<p id="browse"><a href="log.html">Browse the commit log →</a></p>\n' >> "$IDX" 31 printf '</div>\n</body>\n</html>\n' >> "$IDX" 32 33 # Point every README nav link at the rendered page instead of the raw blob. 34 # stagit uses a consistent relative prefix per page depth, so keep group 1. 35 find "$OUT" -name '*.html' -type f -exec sed -i -E \ 36 's|href="((\.\./)*)file/README\.md\.html"|href="\1index.html"|g' {} +