mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #964 from nickzoic/master
Slugify {category} in URLs. Fixes #926
This commit is contained in:
commit
0de44cc844
2 changed files with 24 additions and 3 deletions
|
|
@ -141,14 +141,21 @@ class Content(object):
|
||||||
"""Returns the URL, formatted with the proper values"""
|
"""Returns the URL, formatted with the proper values"""
|
||||||
metadata = copy.copy(self.metadata)
|
metadata = copy.copy(self.metadata)
|
||||||
path = self.metadata.get('path', self.get_relative_source_path())
|
path = self.metadata.get('path', self.get_relative_source_path())
|
||||||
|
default_category = self.settings['DEFAULT_CATEGORY']
|
||||||
|
slug_substitutions = self.settings.get('SLUG_SUBSTITUTIONS', ())
|
||||||
metadata.update({
|
metadata.update({
|
||||||
'path': path_to_url(path),
|
'path': path_to_url(path),
|
||||||
'slug': getattr(self, 'slug', ''),
|
'slug': getattr(self, 'slug', ''),
|
||||||
'lang': getattr(self, 'lang', 'en'),
|
'lang': getattr(self, 'lang', 'en'),
|
||||||
'date': getattr(self, 'date', datetime.now()),
|
'date': getattr(self, 'date', datetime.now()),
|
||||||
'author': getattr(self, 'author', ''),
|
'author': slugify(
|
||||||
'category': getattr(self, 'category',
|
getattr(self, 'author', ''),
|
||||||
self.settings['DEFAULT_CATEGORY']),
|
slug_substitutions
|
||||||
|
),
|
||||||
|
'category': slugify(
|
||||||
|
getattr(self, 'category', default_category),
|
||||||
|
slug_substitutions
|
||||||
|
)
|
||||||
})
|
})
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,20 @@ class TestArticle(TestPage):
|
||||||
custom_article = Article(**article_kwargs)
|
custom_article = Article(**article_kwargs)
|
||||||
self.assertEqual('custom', custom_article.template)
|
self.assertEqual('custom', custom_article.template)
|
||||||
|
|
||||||
|
def test_slugify_category_author(self):
|
||||||
|
settings = get_settings()
|
||||||
|
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()
|
||||||
|
article_kwargs['metadata']['author'] = "O'Brien"
|
||||||
|
article_kwargs['metadata']['category'] = 'C# & stuff'
|
||||||
|
article_kwargs['metadata']['title'] = 'fnord'
|
||||||
|
article_kwargs['settings'] = settings
|
||||||
|
article = Article(**article_kwargs)
|
||||||
|
self.assertEqual(article.url, 'obrien/csharp-stuff/fnord/')
|
||||||
|
self.assertEqual(article.save_as, 'obrien/csharp-stuff/fnord/index.html')
|
||||||
|
|
||||||
|
|
||||||
class TestURLWrapper(unittest.TestCase):
|
class TestURLWrapper(unittest.TestCase):
|
||||||
def test_comparisons(self):
|
def test_comparisons(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue