microblog/app/utils/text.py

9 lines
214 B
Python
Raw Normal View History

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