mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #663 from wking/url-format-metadata
contents: Page.url_format should expose all metadata
This commit is contained in:
commit
08a5ea6fdf
2 changed files with 14 additions and 2 deletions
|
|
@ -114,14 +114,16 @@ class Page(object):
|
|||
|
||||
@property
|
||||
def url_format(self):
|
||||
return {
|
||||
metadata = copy.copy(self.metadata)
|
||||
metadata.update({
|
||||
'slug': getattr(self, 'slug', ''),
|
||||
'lang': getattr(self, 'lang', 'en'),
|
||||
'date': getattr(self, 'date', datetime.now()),
|
||||
'author': getattr(self, 'author', ''),
|
||||
'category': getattr(self, 'category',
|
||||
self.settings['DEFAULT_CATEGORY']),
|
||||
}
|
||||
})
|
||||
return metadata
|
||||
|
||||
def _expand_settings(self, key):
|
||||
fq_key = ('%s_%s' % (self.__class__.__name__, key)).upper()
|
||||
|
|
|
|||
|
|
@ -99,6 +99,16 @@ class TestPage(unittest.TestCase):
|
|||
page = Page(**self.page_kwargs)
|
||||
self.assertEqual(page.save_as, "pages/foo-bar-fr.html")
|
||||
|
||||
def test_metadata_url_format(self):
|
||||
"""Arbitrary metadata should be passed through url_format()
|
||||
"""
|
||||
page = Page(**self.page_kwargs)
|
||||
self.assertIn('summary', page.url_format.keys())
|
||||
page.metadata['directory'] = 'test-dir'
|
||||
page.settings = _DEFAULT_CONFIG.copy()
|
||||
page.settings['PAGE_SAVE_AS'] = '{directory}/{slug}'
|
||||
self.assertEqual(page.save_as, 'test-dir/foo-bar')
|
||||
|
||||
def test_datetime(self):
|
||||
"""If DATETIME is set to a tuple, it should be used to override LOCALE
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue