mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #2406 from mosra/metadata-intrasite-links-process-only-once
Don't process metadata links before all files are present
This commit is contained in:
commit
db586a4c59
6 changed files with 62 additions and 4 deletions
|
|
@ -142,9 +142,9 @@ class Content(object):
|
|||
if not hasattr(self, 'status'):
|
||||
self.status = getattr(self, 'default_status', None)
|
||||
|
||||
if (len(self._context.get('generated_content', [])) > 0 or
|
||||
len(self._context.get('static_content', [])) > 0):
|
||||
self.refresh_metadata_intersite_links()
|
||||
# store the summary metadata if it is set
|
||||
if 'summary' in metadata:
|
||||
self._summary = metadata['summary']
|
||||
|
||||
signals.content_object_init.send(self)
|
||||
|
||||
|
|
@ -469,7 +469,7 @@ class Content(object):
|
|||
|
||||
def refresh_metadata_intersite_links(self):
|
||||
for key in self.settings['FORMATTED_FIELDS']:
|
||||
if key in self.metadata:
|
||||
if key in self.metadata and key != 'summary':
|
||||
value = self._update_content(
|
||||
self.metadata[key],
|
||||
self.get_siteurl()
|
||||
|
|
@ -477,6 +477,16 @@ class Content(object):
|
|||
self.metadata[key] = value
|
||||
setattr(self, key.lower(), value)
|
||||
|
||||
# _summary is an internal variable that some plugins may be writing to,
|
||||
# so ensure changes to it are picked up
|
||||
if ('summary' in self.settings['FORMATTED_FIELDS'] and
|
||||
'summary' in self.metadata):
|
||||
self._summary = self._update_content(
|
||||
self._summary,
|
||||
self.get_siteurl()
|
||||
)
|
||||
self.metadata['summary'] = self._summary
|
||||
|
||||
|
||||
class Page(Content):
|
||||
mandatory_properties = ('title',)
|
||||
|
|
|
|||
7
pelican/tests/cyclic_intersite_links/first-article.rst
Normal file
7
pelican/tests/cyclic_intersite_links/first-article.rst
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
First article
|
||||
#############
|
||||
|
||||
:date: 2018-11-10
|
||||
:summary: Here's the `second <{filename}/second-article.rst>`_,
|
||||
`third <{filename}/third-article.rst>`_ and a
|
||||
`nonexistent article <{filename}/nonexistent.rst>`_.
|
||||
7
pelican/tests/cyclic_intersite_links/second-article.rst
Normal file
7
pelican/tests/cyclic_intersite_links/second-article.rst
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Second article
|
||||
##############
|
||||
|
||||
:date: 2018-11-10
|
||||
:summary: Here's the `first <{filename}/first-article.rst>`_,
|
||||
`third <{filename}/third-article.rst>`_ and a
|
||||
`nonexistent article <{filename}/nonexistent.rst>`_.
|
||||
7
pelican/tests/cyclic_intersite_links/third-article.rst
Normal file
7
pelican/tests/cyclic_intersite_links/third-article.rst
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Third article
|
||||
#############
|
||||
|
||||
:date: 2018-11-10
|
||||
:summary: Here's the `first <{filename}/first-article.rst>`_,
|
||||
`second <{filename}/second-article.rst>`_ and a
|
||||
`nonexistent article <{filename}/nonexistent.rst>`_.
|
||||
|
|
@ -333,6 +333,10 @@ class TestPage(LoggedTestCase):
|
|||
args['metadata']['custom'] = parsed
|
||||
args['context']['localsiteurl'] = 'http://notmyidea.org'
|
||||
p = Page(**args)
|
||||
# This is called implicitly from all generators and Pelican.run() once
|
||||
# all files are processed. Here we process just one page so it needs
|
||||
# to be called explicitly.
|
||||
p.refresh_metadata_intersite_links()
|
||||
self.assertEqual(p.summary, linked)
|
||||
self.assertEqual(p.custom, linked)
|
||||
|
||||
|
|
|
|||
|
|
@ -211,6 +211,29 @@ class TestPelican(LoggedTestCase):
|
|||
msg="Writing .*",
|
||||
level=logging.INFO)
|
||||
|
||||
def test_cyclic_intersite_links_no_warnings(self):
|
||||
settings = read_settings(path=None, override={
|
||||
'PATH': os.path.join(CURRENT_DIR, 'cyclic_intersite_links'),
|
||||
'OUTPUT_PATH': self.temp_path,
|
||||
'CACHE_PATH': self.temp_cache,
|
||||
})
|
||||
pelican = Pelican(settings=settings)
|
||||
mute(True)(pelican.run)()
|
||||
# There are four different intersite links:
|
||||
# - one pointing to the second article from first and third
|
||||
# - one pointing to the first article from second and third
|
||||
# - one pointing to the third article from first and second
|
||||
# - one pointing to a nonexistent from each
|
||||
# If everything goes well, only the warning about the nonexistent
|
||||
# article should be printed. Only two articles are not sufficient,
|
||||
# since the first will always have _context['generated_content'] empty
|
||||
# (thus skipping the link resolving) and the second will always have it
|
||||
# non-empty, containing the first, thus always succeeding.
|
||||
self.assertLogCountEqual(
|
||||
count=1,
|
||||
msg="Unable to find '.*\\.rst', skipping url replacement.",
|
||||
level=logging.WARNING)
|
||||
|
||||
def test_md_extensions_deprecation(self):
|
||||
"""Test that a warning is issued if MD_EXTENSIONS is used"""
|
||||
settings = read_settings(path=None, override={
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue