feat(utils): Added slug function for generate url for products

This commit is contained in:
Black_Raven committed 2026-07-26 20:12:27 +03:00
1 parent 0a6418d84d
commit 0c15ff3059
1 file changed
+19
+19
View File
@@ -0,0 +1,19 @@
import re
TRANSLIT_TABLE = {
'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'e',
'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'y', 'к': 'k', 'л': 'l', 'м': 'm',
'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u',
'ф': 'f', 'х': 'h', 'ц': 'c', 'ч': 'ch', 'ш': 'sh', 'щ': 'sch', 'ъ': '',
'ы': 'y', 'ь': '', 'э': 'e', 'ю': 'yu', 'я': 'ya',
}
def slugify(text: str) -> str:
text = text.lower()
for ru, en in TRANSLIT_TABLE.items():
text = text.replace(ru, en)
text = re.sub(r'[^a-z0-9]+', '-', text)
text = re.sub(r'^-+|-+$', '', text)
return text