Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Copied over pelican summary plugin from base repo which was missing i…

…n mobify pelican fork
  • Loading branch information...
commit a9acbf10ae7ff1e69a7040f68bf4fba784a601c6 1 parent 03bf414
@donnielrt donnielrt authored
Showing with 53 additions and 0 deletions.
  1. +53 −0 pelican/plugins/summary.py
View
53 pelican/plugins/summary.py
@@ -0,0 +1,53 @@
+import types
+
+from pelican import signals
+
+def initialized(pelican):
+ from pelican.settings import _DEFAULT_CONFIG
+ _DEFAULT_CONFIG.setdefault('SUMMARY_BEGIN_MARKER',
+ '<!-- PELICAN_BEGIN_SUMMARY -->')
+ _DEFAULT_CONFIG.setdefault('SUMMARY_END_MARKER',
+ '<!-- PELICAN_END_SUMMARY -->')
+ if pelican:
+ pelican.settings.setdefault('SUMMARY_BEGIN_MARKER',
+ '<!-- PELICAN_BEGIN_SUMMARY -->')
+ pelican.settings.setdefault('SUMMARY_END_MARKER',
+ '<!-- PELICAN_END_SUMMARY -->')
+
+def content_object_init(self_class, instance):
+ # if summary is already specified, use it
+ if 'summary' in instance.metadata:
+ return
+
+ def _get_content(self):
+ content = self._content
+ if self.settings['SUMMARY_BEGIN_MARKER']:
+ content = content.replace(
+ self.settings['SUMMARY_BEGIN_MARKER'], '', 1)
+ if self.settings['SUMMARY_END_MARKER']:
+ content = content.replace(
+ self.settings['SUMMARY_END_MARKER'], '', 1)
+ return content
+ instance._get_content = types.MethodType(_get_content, instance)
+
+ # extract out our summary
+ if not hasattr(instance, '_summary') and instance._content is not None:
+ 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)
+ signals.content_object_init.connect(content_object_init)
Please sign in to comment.
Something went wrong with that request. Please try again.