forked from github/pelican
Bug #1493 — Memoize slugify when possible
This commit is contained in:
parent
7feb638b5c
commit
e39dc95c3b
3 changed files with 4 additions and 2 deletions
|
|
@ -388,7 +388,7 @@ class TestArticle(TestPage):
|
||||||
|
|
||||||
def test_slugify_category_author(self):
|
def test_slugify_category_author(self):
|
||||||
settings = get_settings()
|
settings = get_settings()
|
||||||
settings['SLUG_SUBSTITUTIONS'] = [ ('C#', 'csharp') ]
|
settings['SLUG_SUBSTITUTIONS'] = (('C#', 'csharp'),)
|
||||||
settings['ARTICLE_URL'] = '{author}/{category}/{slug}/'
|
settings['ARTICLE_URL'] = '{author}/{category}/{slug}/'
|
||||||
settings['ARTICLE_SAVE_AS'] = '{author}/{category}/{slug}/index.html'
|
settings['ARTICLE_SAVE_AS'] = '{author}/{category}/{slug}/index.html'
|
||||||
article_kwargs = self._copy_page_kwargs()
|
article_kwargs = self._copy_page_kwargs()
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@ class URLWrapper(object):
|
||||||
return self.slug
|
return self.slug
|
||||||
|
|
||||||
def _normalize_key(self, key):
|
def _normalize_key(self, key):
|
||||||
|
if hasattr(key, 'name'):
|
||||||
|
key = key.name
|
||||||
subs = self.settings.get('SLUG_SUBSTITUTIONS', ())
|
subs = self.settings.get('SLUG_SUBSTITUTIONS', ())
|
||||||
return six.text_type(slugify(key, subs))
|
return six.text_type(slugify(key, subs))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,7 @@ def pelican_open(filename):
|
||||||
content = content[1:]
|
content = content[1:]
|
||||||
yield content
|
yield content
|
||||||
|
|
||||||
|
@memoized
|
||||||
def slugify(value, substitutions=()):
|
def slugify(value, substitutions=()):
|
||||||
"""
|
"""
|
||||||
Normalizes string, converts to lowercase, removes non-alpha characters,
|
Normalizes string, converts to lowercase, removes non-alpha characters,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue