mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Add AUTHOR_SUBSTITUTIONS
This commit is contained in:
parent
648165b839
commit
fcd4f9aa0d
5 changed files with 44 additions and 1 deletions
|
|
@ -12,6 +12,9 @@ Next release
|
||||||
``TAG_SUBSTITUTIONS`` and ``CATEGORY_SUBSTITUTIONS`` settings. These also
|
``TAG_SUBSTITUTIONS`` and ``CATEGORY_SUBSTITUTIONS`` settings. These also
|
||||||
allow for keeping non-alphanum characters for backward compatibility with
|
allow for keeping non-alphanum characters for backward compatibility with
|
||||||
existing URLs.
|
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)
|
3.6.3 (2015-08-14)
|
||||||
==================
|
==================
|
||||||
|
|
|
||||||
|
|
@ -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
|
applied in order. ``skip`` is a boolean indicating whether
|
||||||
or not to skip replacement of non-alphanumeric characters.
|
or not to skip replacement of non-alphanumeric characters.
|
||||||
Useful for backward compatibility with existing URLs.
|
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.
|
``CATEGORY_SUBSTITUTIONS = ()`` Added to ``SLUG_SUBSTITUTIONS`` for categories.
|
||||||
``TAG_SUBSTITUTIONS = ()`` Added to ``SLUG_SUBSTITUTIONS`` for tags.
|
``TAG_SUBSTITUTIONS = ()`` Added to ``SLUG_SUBSTITUTIONS`` for tags.
|
||||||
====================================================== ==============================================================
|
====================================================== ==============================================================
|
||||||
|
|
|
||||||
|
|
@ -457,6 +457,23 @@ class TestArticle(TestPage):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
article.save_as, 'obrien/csharp-stuff/fnord/index.html')
|
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):
|
def test_slugify_category_with_dots(self):
|
||||||
settings = get_settings()
|
settings = get_settings()
|
||||||
settings['CATEGORY_SUBSTITUTIONS'] = [('Fedora QA', 'fedora.qa', True)]
|
settings['CATEGORY_SUBSTITUTIONS'] = [('Fedora QA', 'fedora.qa', True)]
|
||||||
|
|
|
||||||
|
|
@ -71,3 +71,19 @@ class TestURLWrapper(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(tag.slug, 'tag.dot')
|
self.assertEqual(tag.slug, 'tag.dot')
|
||||||
self.assertEqual(cat.slug, 'cat.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')
|
||||||
|
|
|
||||||
|
|
@ -136,4 +136,9 @@ class Tag(URLWrapper):
|
||||||
|
|
||||||
|
|
||||||
class Author(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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue