23 lines
937 B
Bash
Executable file
23 lines
937 B
Bash
Executable file
#!/usr/bin/env bash
|
|
# =============================================================================
|
|
# skills/ingest/scripts/slug.sh
|
|
# Derive a wiki slug from a path, filename, or title string.
|
|
# slug.sh "raw/articles/My Source.md" -> my-source
|
|
# slug.sh "Some Concept Name" -> some-concept-name
|
|
# =============================================================================
|
|
set -euo pipefail
|
|
|
|
input="${1:?usage: slug.sh <path-or-title>}"
|
|
|
|
# Strip directory and extension when given a path
|
|
base="${input##*/}"
|
|
base="${base%.*}"
|
|
|
|
slug="$(printf '%s\n' "$base" \
|
|
| tr '[:upper:]' '[:lower:]' \
|
|
| 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"
|