1
0
Fork 0
forked from github/pelican

Preserve category case in importer

Adds a `preserve_case` parameter to the `slugify()` function and uses it
to preserve capital letters in category names when using the Pelican
importer.
This commit is contained in:
Justin Mayer 2020-04-15 20:42:21 +02:00
commit 8ba00dd9f1
4 changed files with 16 additions and 7 deletions

View file

@ -222,7 +222,7 @@ def pelican_open(filename, mode='r', strip_crs=(sys.platform == 'win32')):
yield content
def slugify(value, regex_subs=()):
def slugify(value, regex_subs=(), preserve_case=False):
"""
Normalizes string, converts to lowercase, removes non-alpha characters,
and converts spaces to hyphens.
@ -245,7 +245,8 @@ def slugify(value, regex_subs=()):
value = re.sub(src, dst, value, flags=re.IGNORECASE)
# convert to lowercase
value = value.lower()
if not preserve_case:
value = value.lower()
# we want only ASCII chars
value = value.encode('ascii', 'ignore').strip()