Skip to content

fix: transliterate non-Latin titles/filenames in _slugify() - #15

Merged
punchagan merged 1 commit into
mainfrom
slugify-unidecode
Aug 7, 2026
Merged

punchagan merged 1 commit into
mainfrom
slugify-unidecode

Conversation

@punchagan

Copy link
Copy Markdown
Owner

Summary

  • _slugify() only kept [a-z0-9], so a title in a non-Latin script (Telugu, Devanagari, etc. — Patr's own namesake, पत्र/పత్రం, is exactly this case) slugified to an empty string. new_edition() had no guard, so a second non-Latin-titled edition would silently collide at CONTENT_DIR/"" instead of erroring cleanly, and every non-Latin image upload landed on the same image.jpg/image-<hex>.jpg fallback name.
  • Accented Latin text (e.g. "café") was also silently mangled (caf-na-ve) rather than transliterated.
  • Added unidecode (MIT, no transitive deps) to transliterate to ASCII before stripping non-alphanumerics — "café" → "cafe", "పత్రం" → "ptrn". new_edition() now falls back to "untitled" for titles with no transliterable characters at all (pure punctuation/emoji), matching the existing "image" fallback already used for uploads.

Test plan

  • New tests: non-Latin edition title, punctuation-only title fallback, non-Latin image filename — all reproduced red against the old code first
  • Updated test_unicode_title_round_trips — the transliterated slug now includes the non-Latin part instead of dropping it
  • uv run ruff check --unsafe-fixes --fix / uv run ruff format
  • uv run --extra dev pytest — 425 passed

🤖 Generated with Claude Code

_slugify() only kept [a-z0-9] characters, so a title in a non-Latin
script (Telugu, Devanagari, etc. — Patr's own namesake, पत्र/పత్రం, is
exactly this case) slugified to an empty string. new_edition() had no
guard against that, so it would collide with any other non-Latin
edition at CONTENT_DIR/"" instead of erroring cleanly, and every
non-Latin image upload landed on the same image.jpg/image-<hex>.jpg
fallback. Accented Latin text (e.g. "café") was also silently
mangled rather than transliterated.

Add unidecode to transliterate to ASCII before stripping
non-alphanumerics, and fall back to "untitled" in new_edition() for
titles with no transliterable characters at all (pure punctuation or
emoji), matching the existing "image" fallback for uploads.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@punchagan
punchagan merged commit 3482a23 into main Aug 7, 2026
2 checks passed
@punchagan
punchagan deleted the slugify-unidecode branch August 7, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant