feat: custom newsletter slug

This commit is contained in:
Leon
2025-07-24 13:20:22 +02:00
parent f78607f506
commit 24e65a8c86
19 changed files with 386 additions and 68 deletions

18
backend/app/core/slug.py Normal file
View File

@@ -0,0 +1,18 @@
import re
def sanitize_slug(slug: str | None) -> str | None:
"""Sanitize a string to be used as a URL slug.
- Converts to lowercase
- Replaces spaces and underscores with hyphens
- Removes characters that are not alphanumeric or hyphens
- Removes leading/trailing hyphens
"""
if not slug:
return None
slug = slug.lower()
slug = re.sub(r"[\s_]+", "-", slug)
slug = re.sub(r"[^a-z0-9-]", "", slug)
slug = slug.strip("-")
return slug or None