feat(ingest): Refine slug generation with validation

This commit is contained in:
Matteo Cherubini 2026-06-05 09:59:18 +02:00
parent 6d1151fa5a
commit 203fbadd63
2 changed files with 8 additions and 3 deletions

View file

@ -36,7 +36,7 @@ contradictions="$(jq -r '.contradictions // "None"' "$manifest")"
[[ -n "$raw_source" && "$raw_source" != "null" ]] || fail "manifest" "raw_source missing"
slug="$(bash "${SCRIPTS}/slug.sh" "$raw_source")"
slug="$(bash "${SCRIPTS}/slug.sh" "$raw_source")" || fail "slug" "empty or invalid slug for ${raw_source}"
# --- collect touched paths ---
mapfile -t created_paths < <(jq -r '.pages[] | select(.status=="created") | .path' "$manifest")

View file

@ -13,6 +13,11 @@ input="${1:?usage: slug.sh <path-or-title>}"
base="${input##*/}"
base="${base%.*}"
printf '%s\n' "$base" \
slug="$(printf '%s\n' "$base" \
| tr '[:upper:]' '[:lower:]' \
| sed -E 's/[^a-z0-9]+/-/g; s/-{2,}/-/g; s/^-+//; s/-+$//'
| sed -E 's/[^a-z0-9]+/-/g; s/-{2,}/-/g; s/^-+//; s/-+$//')"
# An all-symbols input (e.g. "!!!.md") collapses to "" — refuse rather than emit a
# broken/empty slug that would produce an invalid branch name downstream.
[[ -n "$slug" ]] || { echo "slug: empty result for input '${input}'" >&2; exit 1; }
printf '%s\n' "$slug"