mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
preserve_case option for category names slugify (fix #2248)
This commit is contained in:
parent
56a483475b
commit
232e0b2169
3 changed files with 8 additions and 6 deletions
|
|
@ -88,7 +88,7 @@ class TestWordpressXmlImporter(unittest.TestCase):
|
|||
index = 0
|
||||
for post in test_posts:
|
||||
name = post[2]
|
||||
category = slugify(post[5][0])
|
||||
category = slugify(post[5][0], preserve_case=True)
|
||||
name += '.md'
|
||||
filename = os.path.join(category, name)
|
||||
out_name = fnames[index]
|
||||
|
|
@ -164,7 +164,7 @@ class TestWordpressXmlImporter(unittest.TestCase):
|
|||
for post in test_posts:
|
||||
name = post[2]
|
||||
kind = post[8]
|
||||
category = slugify(post[5][0])
|
||||
category = slugify(post[5][0], preserve_case=True)
|
||||
name += '.md'
|
||||
filename = os.path.join(kind, category, name)
|
||||
out_name = fnames[index]
|
||||
|
|
|
|||
|
|
@ -598,7 +598,7 @@ def get_out_filename(output_path, filename, ext, kind,
|
|||
typename = ''
|
||||
kind = 'article'
|
||||
if dircat and (len(categories) > 0):
|
||||
catname = slugify(categories[0])
|
||||
catname = slugify(categories[0], preserve_case=True)
|
||||
else:
|
||||
catname = ''
|
||||
out_filename = os.path.join(output_path, typename,
|
||||
|
|
@ -607,7 +607,7 @@ def get_out_filename(output_path, filename, ext, kind,
|
|||
os.makedirs(os.path.join(output_path, typename, catname))
|
||||
# option to put files in directories with categories names
|
||||
elif dircat and (len(categories) > 0):
|
||||
catname = slugify(categories[0])
|
||||
catname = slugify(categories[0], preserve_case=True)
|
||||
out_filename = os.path.join(output_path, catname, filename + ext)
|
||||
if not os.path.isdir(os.path.join(output_path, catname)):
|
||||
os.mkdir(os.path.join(output_path, catname))
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ def pelican_open(filename, mode='rb', strip_crs=(sys.platform == 'win32')):
|
|||
yield content
|
||||
|
||||
|
||||
def slugify(value, substitutions=()):
|
||||
def slugify(value, substitutions=(), preserve_case=False):
|
||||
"""
|
||||
Normalizes string, converts to lowercase, removes non-alpha characters,
|
||||
and converts spaces to hyphens.
|
||||
|
|
@ -281,7 +281,9 @@ def slugify(value, substitutions=()):
|
|||
if isinstance(value, six.binary_type):
|
||||
value = value.decode('ascii')
|
||||
# still unicode
|
||||
value = unicodedata.normalize('NFKD', value).lower()
|
||||
value = unicodedata.normalize('NFKD', value)
|
||||
if not preserve_case:
|
||||
value = value.lower()
|
||||
|
||||
# backward compatible covert from 2-tuples to 3-tuples
|
||||
new_subs = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue