From e39dc95c3bfed28fffc972e1fa780b772e61701c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Thu, 9 Oct 2014 11:27:53 +0200 Subject: [PATCH] =?UTF-8?q?Bug=20#1493=20=E2=80=94=C2=A0Memoize=20slugify?= =?UTF-8?q?=20when=20possible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pelican/tests/test_contents.py | 2 +- pelican/urlwrappers.py | 2 ++ pelican/utils.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py index e64b3804..e880f079 100644 --- a/pelican/tests/test_contents.py +++ b/pelican/tests/test_contents.py @@ -388,7 +388,7 @@ class TestArticle(TestPage): def test_slugify_category_author(self): settings = get_settings() - settings['SLUG_SUBSTITUTIONS'] = [ ('C#', 'csharp') ] + settings['SLUG_SUBSTITUTIONS'] = (('C#', 'csharp'),) settings['ARTICLE_URL'] = '{author}/{category}/{slug}/' settings['ARTICLE_SAVE_AS'] = '{author}/{category}/{slug}/index.html' article_kwargs = self._copy_page_kwargs() diff --git a/pelican/urlwrappers.py b/pelican/urlwrappers.py index f92d1963..7b957532 100644 --- a/pelican/urlwrappers.py +++ b/pelican/urlwrappers.py @@ -41,6 +41,8 @@ class URLWrapper(object): return self.slug def _normalize_key(self, key): + if hasattr(key, 'name'): + key = key.name subs = self.settings.get('SLUG_SUBSTITUTIONS', ()) return six.text_type(slugify(key, subs)) diff --git a/pelican/utils.py b/pelican/utils.py index 1f8cb0a6..6286cfd2 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -239,7 +239,7 @@ def pelican_open(filename): content = content[1:] yield content - +@memoized def slugify(value, substitutions=()): """ Normalizes string, converts to lowercase, removes non-alpha characters,