4cb319b393
slugify() produces ASCII-only lowercase slugs from arbitrary text (used for artist slugs and tag slugs). paths.derive_subdir/derive_top_level_artist extract the destination layout and folder→artist convention from an import source path. hash_suffixed_name builds IR-style 'stem__hash10.ext' filenames. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
23 lines
629 B
Python
23 lines
629 B
Python
"""Slug generation for artists, tags, and paths."""
|
|
|
|
import re
|
|
import unicodedata
|
|
|
|
_SLUG_RE = re.compile(r"[^a-z0-9]+")
|
|
|
|
|
|
def slugify(value: str) -> str:
|
|
"""Lowercase ASCII slug. Empty input becomes 'untitled'.
|
|
|
|
Examples:
|
|
slugify("Bob Ross") -> "bob-ross"
|
|
slugify("hello, world!") -> "hello-world"
|
|
slugify("naïve café") -> "naive-cafe"
|
|
"""
|
|
if not value:
|
|
return "untitled"
|
|
normalized = unicodedata.normalize("NFKD", value).encode("ascii", "ignore").decode()
|
|
normalized = normalized.lower()
|
|
slug = _SLUG_RE.sub("-", normalized).strip("-")
|
|
return slug or "untitled"
|