From a4b65ac09f315902cf5072bb9ae5cdce3efeaaaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles=20Fl=C3=A8che?= Date: Sat, 14 Oct 2017 02:31:44 +0700 Subject: [PATCH] Fix intrasite links for non-'summary' metadata Only the summary gets its intrasite links processed, has its value is either generated from the content (calling self._update_content at some point) or self._update_content is explicitly called if summary is passed as metadata. This patch expands the paths as soon as possible in (Content init) for metadata defined in FORMATTED_FIELDS. --- pelican/contents.py | 10 ++++++++++ pelican/tests/test_contents.py | 14 +++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index 15770fc8..2494edbb 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -140,6 +140,16 @@ class Content(object): if not hasattr(self, 'status'): self.status = getattr(self, 'default_status', None) + for key in self.settings['FORMATTED_FIELDS']: + if key in self.metadata: + value = self._update_content( + self.metadata[key], + self.get_siteurl() + ) + self.metadata[key] = value + setattr(self, key.lower(), value) + + # store the summary metadata if it is set if 'summary' in metadata: self._summary = metadata['summary'] diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py index d028c7a1..edd91fb6 100644 --- a/pelican/tests/test_contents.py +++ b/pelican/tests/test_contents.py @@ -319,17 +319,21 @@ class TestPage(LoggedTestCase): ) # also test for summary in metadata - args['metadata']['summary'] = ( + parsed = ( 'A simple summary test, with a ' 'link' ) - args['context']['localsiteurl'] = 'http://notmyidea.org' - p = Page(**args) - self.assertEqual( - p.summary, + linked = ( 'A simple summary test, with a ' 'link' ) + args['settings']['FORMATTED_FIELDS'] = ['summary', 'custom'] + args['metadata']['summary'] = parsed + args['metadata']['custom'] = parsed + args['context']['localsiteurl'] = 'http://notmyidea.org' + p = Page(**args) + self.assertEqual(p.summary, linked) + self.assertEqual(p.custom, linked) def test_intrasite_link_more(self): # type does not take unicode in PY2 and bytes in PY3, which in