microblog.pub/app/utils/text.py
2022-10-30 17:51:57 +01:00

8 lines
214 B
Python

import re
import unicodedata
def slugify(text: str) -> str:
value = unicodedata.normalize("NFKC", text)
value = re.sub(r"[^\w\s-]", "", value.lower())
return re.sub(r"[-\s]+", "-", value).strip("-_")