forked from github/pelican
update summary plugin so that tests are fixed (hopefully)
This commit is contained in:
parent
d68d2debf9
commit
03f87057c2
1 changed files with 20 additions and 27 deletions
|
|
@ -19,17 +19,8 @@ def content_object_init(instance):
|
|||
if 'summary' in instance.metadata:
|
||||
return
|
||||
|
||||
try:
|
||||
content = instance.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)
|
||||
def _get_content(self):
|
||||
content = self._content
|
||||
if self.settings['SUMMARY_BEGIN_MARKER']:
|
||||
content = content.replace(
|
||||
self.settings['SUMMARY_BEGIN_MARKER'], '', 1)
|
||||
|
|
@ -37,23 +28,25 @@ def content_object_init(instance):
|
|||
content = content.replace(
|
||||
self.settings['SUMMARY_END_MARKER'], '', 1)
|
||||
return content
|
||||
instance.get_content = types.MethodType(get_content, instance)
|
||||
|
||||
instance._get_content = types.MethodType(_get_content, instance)
|
||||
|
||||
# extract out our summary
|
||||
begin_summary = -1
|
||||
end_summary = -1
|
||||
if instance.settings['SUMMARY_BEGIN_MARKER']:
|
||||
begin_summary = content.find(instance.settings['SUMMARY_BEGIN_MARKER'])
|
||||
if instance.settings['SUMMARY_END_MARKER']:
|
||||
end_summary = content.find(instance.settings['SUMMARY_END_MARKER'])
|
||||
if begin_summary != -1 or end_summary != -1:
|
||||
# the beginning position has to take into account the length
|
||||
# of the marker
|
||||
begin_summary = (begin_summary +
|
||||
len(instance.settings['SUMMARY_BEGIN_MARKER'])
|
||||
if begin_summary != -1 else 0)
|
||||
end_summary = end_summary if end_summary != -1 else None
|
||||
instance._summary = content[begin_summary:end_summary]
|
||||
if not hasattr(instance, '_summary'):
|
||||
content = instance._content
|
||||
begin_summary = -1
|
||||
end_summary = -1
|
||||
if instance.settings['SUMMARY_BEGIN_MARKER']:
|
||||
begin_summary = content.find(instance.settings['SUMMARY_BEGIN_MARKER'])
|
||||
if instance.settings['SUMMARY_END_MARKER']:
|
||||
end_summary = content.find(instance.settings['SUMMARY_END_MARKER'])
|
||||
if begin_summary != -1 or end_summary != -1:
|
||||
# the beginning position has to take into account the length
|
||||
# of the marker
|
||||
begin_summary = (begin_summary +
|
||||
len(instance.settings['SUMMARY_BEGIN_MARKER'])
|
||||
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():
|
||||
signals.initialized.connect(initialized)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue