Slugify a string, to make it URL friendly.
(value: str, separator: str, unicode: bool = False)
| 36 | |
| 37 | |
| 38 | def slugify(value: str, separator: str, unicode: bool = False) -> str: |
| 39 | """ Slugify a string, to make it URL friendly. """ |
| 40 | if not unicode: |
| 41 | # Replace Extended Latin characters with ASCII, i.e. `žlutý` => `zluty` |
| 42 | value = unicodedata.normalize('NFKD', value) |
| 43 | value = value.encode('ascii', 'ignore').decode('ascii') |
| 44 | value = re.sub(r'[^\w\s-]', '', value).strip().lower() |
| 45 | return re.sub(r'[{}\s]+'.format(separator), separator, value) |
| 46 | |
| 47 | |
| 48 | def slugify_unicode(value: str, separator: str) -> str: |