1
0
Fork 0
forked from github/pelican

Add AUTHOR_SUBSTITUTIONS

This commit is contained in:
Mr. Senko 2016-04-01 23:01:57 +03:00
commit fcd4f9aa0d
5 changed files with 44 additions and 1 deletions

View file

@ -12,6 +12,9 @@ Next release
``TAG_SUBSTITUTIONS`` and ``CATEGORY_SUBSTITUTIONS`` settings. These also
allow for keeping non-alphanum characters for backward compatibility with
existing URLs.
* Author slugs can be controlled with greater precision using the
``AUTHOR_SUBSTITUTIONS`` setting. Keeping non-alphanum characters is supported
as well but discouraged.
3.6.3 (2015-08-14)
==================

View file

@ -310,6 +310,8 @@ Setting name (followed by default value, if any) What does it do?
applied in order. ``skip`` is a boolean indicating whether
or not to skip replacement of non-alphanumeric characters.
Useful for backward compatibility with existing URLs.
``AUTHOR_SUBSTITUTIONS = ()`` Substitutions for authors. ``SLUG_SUBSTITUTIONS`` is not
taken into account here!
``CATEGORY_SUBSTITUTIONS = ()`` Added to ``SLUG_SUBSTITUTIONS`` for categories.
``TAG_SUBSTITUTIONS = ()`` Added to ``SLUG_SUBSTITUTIONS`` for tags.
====================================================== ==============================================================

View file

@ -457,6 +457,23 @@ class TestArticle(TestPage):
self.assertEqual(
article.save_as, 'obrien/csharp-stuff/fnord/index.html')
def test_slugify_with_author_substitutions(self):
settings = get_settings()
settings['AUTHOR_SUBSTITUTIONS'] = [
('Alexander Todorov', 'atodorov', False),
('Krasimir Tsonev', 'krasimir', False),
]
settings['ARTICLE_URL'] = 'blog/{author}/{slug}/'
settings['ARTICLE_SAVE_AS'] = 'blog/{author}/{slug}/index.html'
article_kwargs = self._copy_page_kwargs()
article_kwargs['metadata']['author'] = Author('Alexander Todorov',
settings)
article_kwargs['metadata']['title'] = 'fnord'
article_kwargs['settings'] = settings
article = Article(**article_kwargs)
self.assertEqual(article.url, 'blog/atodorov/fnord/')
self.assertEqual(article.save_as, 'blog/atodorov/fnord/index.html')
def test_slugify_category_with_dots(self):
settings = get_settings()
settings['CATEGORY_SUBSTITUTIONS'] = [('Fedora QA', 'fedora.qa', True)]

View file

@ -71,3 +71,19 @@ class TestURLWrapper(unittest.TestCase):
self.assertEqual(tag.slug, 'tag.dot')
self.assertEqual(cat.slug, 'cat.dot')
def test_author_slug_substitutions(self):
settings = {
'AUTHOR_SUBSTITUTIONS': [
('Alexander Todorov', 'atodorov', False),
('Krasimir Tsonev', 'krasimir', False),
]
}
author1 = Author('Mr. Senko', settings=settings)
author2 = Author('Alexander Todorov', settings=settings)
author3 = Author('Krasimir Tsonev', settings=settings)
self.assertEqual(author1.slug, 'mr-senko')
self.assertEqual(author2.slug, 'atodorov')
self.assertEqual(author3.slug, 'krasimir')

View file

@ -136,4 +136,9 @@ class Tag(URLWrapper):
class Author(URLWrapper):
pass
@property
def slug(self):
if self._slug is None:
self._slug = slugify(self.name,
self.settings.get('AUTHOR_SUBSTITUTIONS', ()))
return self._slug