From c985dd84c33bae70c9b0370844bc4d7dd39bcf15 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 30 Oct 2022 17:51:57 +0100 Subject: [PATCH] Add slugify helper --- app/utils/text.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 app/utils/text.py diff --git a/app/utils/text.py b/app/utils/text.py new file mode 100644 index 0000000..1505950 --- /dev/null +++ b/app/utils/text.py @@ -0,0 +1,8 @@ +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("-_")