Files
project-work/worker-toolkit-stocks-in-the-future/repo/docs/map/_meta/build-index.sh

36 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Rebuild objects/_index.md from card frontmatter.
#
# The index is generated, never hand-edited: a hand-curated index drifts, a derived one
# cannot. Run after adding, moving, or re-verifying any object card.
set -euo pipefail
map_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
objects_dir="${map_dir}/objects"
out="${objects_dir}/_index.md"
field() { awk -v k="^$2:" '$0 ~ k { sub(/^[^:]*: */, ""); print; exit }' "$1"; }
{
echo "# Object index"
echo
echo "One line per noun. Open the card, not the folder."
echo
echo "_Generated by \`_meta/build-index.sh\` from card frontmatter. Do not hand-edit._"
echo
echo "| Noun | Cluster | Universe | Status | Owning file |"
echo "|---|---|---|---|---|"
find "$objects_dir" -name '*.md' ! -name '_index.md' ! -name 'CONTEXT.md' \
| sort | while read -r f; do
rel="${f#"${objects_dir}"/}"
name=$(awk '/^# /{ sub(/^# /, ""); print; exit }' "$f")
printf '| [%s](%s) | %s | %s | %s | `%s` |\n' \
"$name" "$rel" "$(field "$f" cluster)" "$(field "$f" universe)" \
"$(field "$f" status)" "$(field "$f" entity)"
done
} > "$out"
echo "wrote $out ($(grep -c '^| \[' "$out") cards)"