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

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import locale
import os
@ -138,7 +138,7 @@ class TestWordpressXmlImporter(unittest.TestCase):
index = 0
for post in test_posts:
name = post[2]
category = slugify(post[5][0], regex_subs=subs)
category = slugify(post[5][0], regex_subs=subs, preserve_case=True)
name += '.md'
filename = os.path.join(category, name)
out_name = fnames[index]
@ -215,7 +215,7 @@ class TestWordpressXmlImporter(unittest.TestCase):
for post in test_posts:
name = post[2]
kind = post[8]
category = slugify(post[5][0], regex_subs=subs)
category = slugify(post[5][0], regex_subs=subs, preserve_case=True)
name += '.md'
filename = os.path.join(kind, category, name)
out_name = fnames[index]

View file

@ -122,6 +122,12 @@ class TestUtils(LoggedTestCase):
for value, expected in samples:
self.assertEqual(utils.slugify(value, regex_subs=subs), expected)
self.assertEqual(utils.slugify('Cat', regex_subs=subs), 'cat')
self.assertEqual(
utils.slugify('Cat', regex_subs=subs, preserve_case=False), 'cat')
self.assertEqual(
utils.slugify('Cat', regex_subs=subs, preserve_case=True), 'Cat')
def test_slugify_substitute(self):
samples = (('C++ is based on C', 'cpp-is-based-on-c'),