mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #745 from bbinet/fix-tests-717
Fix regression introduced in #716
This commit is contained in:
commit
80edafbe50
2 changed files with 22 additions and 31 deletions
|
|
@ -112,7 +112,7 @@ class Page(object):
|
||||||
if 'summary' in metadata:
|
if 'summary' in metadata:
|
||||||
self._summary = metadata['summary']
|
self._summary = metadata['summary']
|
||||||
|
|
||||||
signals.content_object_init.send(self.__class__, instance=self)
|
signals.content_object_init.send(self)
|
||||||
|
|
||||||
def check_properties(self):
|
def check_properties(self):
|
||||||
"""test that each mandatory property is set."""
|
"""test that each mandatory property is set."""
|
||||||
|
|
|
||||||
|
|
@ -14,24 +14,13 @@ def initialized(pelican):
|
||||||
pelican.settings.setdefault('SUMMARY_END_MARKER',
|
pelican.settings.setdefault('SUMMARY_END_MARKER',
|
||||||
'<!-- PELICAN_END_SUMMARY -->')
|
'<!-- PELICAN_END_SUMMARY -->')
|
||||||
|
|
||||||
def content_object_init(PageClass, instance):
|
def content_object_init(instance):
|
||||||
# if summary is already specified, use it
|
# if summary is already specified, use it
|
||||||
if 'summary' in instance.metadata:
|
if 'summary' in instance.metadata:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
def _get_content(self):
|
||||||
content = instance.content
|
content = self._content
|
||||||
except:
|
|
||||||
# in some tests, this fails because a context has not been set
|
|
||||||
return
|
|
||||||
|
|
||||||
# monkey patch a new function around get_content that removes summary
|
|
||||||
# markers
|
|
||||||
prev_get_content = instance.get_content
|
|
||||||
def get_content(self, siteurl):
|
|
||||||
content = prev_get_content(siteurl)
|
|
||||||
self.settings['SUMMARY_BEGIN_MARKER'] = '<!-- PELICAN_BEGIN_SUMMARY -->'
|
|
||||||
self.settings['SUMMARY_END_MARKER'] = '<!-- PELICAN_END_SUMMARY -->'
|
|
||||||
if self.settings['SUMMARY_BEGIN_MARKER']:
|
if self.settings['SUMMARY_BEGIN_MARKER']:
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
self.settings['SUMMARY_BEGIN_MARKER'], '', 1)
|
self.settings['SUMMARY_BEGIN_MARKER'], '', 1)
|
||||||
|
|
@ -39,23 +28,25 @@ def content_object_init(PageClass, instance):
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
self.settings['SUMMARY_END_MARKER'], '', 1)
|
self.settings['SUMMARY_END_MARKER'], '', 1)
|
||||||
return content
|
return content
|
||||||
instance.get_content = types.MethodType(get_content, instance)
|
instance._get_content = types.MethodType(_get_content, instance)
|
||||||
|
|
||||||
# extract out our summary
|
# extract out our summary
|
||||||
begin_summary = -1
|
if not hasattr(instance, '_summary'):
|
||||||
end_summary = -1
|
content = instance._content
|
||||||
if instance.settings['SUMMARY_BEGIN_MARKER']:
|
begin_summary = -1
|
||||||
begin_summary = content.find(instance.settings['SUMMARY_BEGIN_MARKER'])
|
end_summary = -1
|
||||||
if instance.settings['SUMMARY_END_MARKER']:
|
if instance.settings['SUMMARY_BEGIN_MARKER']:
|
||||||
end_summary = content.find(instance.settings['SUMMARY_END_MARKER'])
|
begin_summary = content.find(instance.settings['SUMMARY_BEGIN_MARKER'])
|
||||||
if begin_summary != -1 or end_summary != -1:
|
if instance.settings['SUMMARY_END_MARKER']:
|
||||||
# the beginning position has to take into account the length
|
end_summary = content.find(instance.settings['SUMMARY_END_MARKER'])
|
||||||
# of the marker
|
if begin_summary != -1 or end_summary != -1:
|
||||||
begin_summary = (begin_summary +
|
# the beginning position has to take into account the length
|
||||||
len(instance.settings['SUMMARY_BEGIN_MARKER'])
|
# of the marker
|
||||||
if begin_summary != -1 else 0)
|
begin_summary = (begin_summary +
|
||||||
end_summary = end_summary if end_summary != -1 else None
|
len(instance.settings['SUMMARY_BEGIN_MARKER'])
|
||||||
instance._summary = content[begin_summary:end_summary]
|
if begin_summary != -1 else 0)
|
||||||
|
end_summary = end_summary if end_summary != -1 else None
|
||||||
|
instance._summary = content[begin_summary:end_summary]
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
signals.initialized.connect(initialized)
|
signals.initialized.connect(initialized)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue