microblog.pub/app/utils/text.py

9 lines
214 B
Python
Raw Normal View History

2022-10-30 17:51:57 +01:00
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("-_")