#!/bin/bash ## ## Builds the glove-box cheat sheet: a Location | Item | Qty table, read ## from the Loadout list in this post's outline. The outline stays the one ## place the gear list is written down; this sheet never drifts from it. ## ## In the outline, the list looks like: ## ## - The Loadout ## - Glove Box <- location ## - Tissues x 3 - commentary <- item; " xN" is the quantity, ## anything after " - " is dropped ## ## Usage: mkhtml [outline.org] > sheet.html ## POST=$(realpath $(dirname $0)/..) OUTLINE=${1:-$POST/outline.org} ETC=$POST/etc loadout_rows() { awk ' /^\* / { in_outline = ($0 == "* Outline"); next } !in_outline { next } /^- / { in_loadout = tolower($0) ~ /^- (the )?loadout/; next } !in_loadout { next } /^ - / { sub(/^ - /, ""); location = $0; next } /^ - / { sub(/^ - /, "") sub(/ - .*/, "") qty = 1 if (match($0, / x ?[0-9]+$/)) { qty = substr($0, RSTART) gsub(/[^0-9]/, "", qty) $0 = substr($0, 1, RSTART - 1) } print location "\t" $0 "\t" qty } ' "$OUTLINE" } html_escape() { sed -e 's/&/\&/g' -e 's/\</g' -e 's/>/\>/g' } org_links_to_labels() { sed -E -e 's/\[\[[^]]*\]\[([^]]*)\]\]/\1/g' -e 's/\[\[([^]]*)\]\]/\1/g' } table_rows() { loadout_rows | org_links_to_labels | html_escape | awk -F'\t' ' { shown = ($1 == previous) ? "" : $1 class = ($1 == previous) ? "" : " class=\"group\"" printf "