Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Created summary pelican plugin #4

Merged
merged 2 commits into from over 1 year ago

2 participants

Donniel Thomas John Boxall
Donniel Thomas
Collaborator

Copied over pelican summary plugin from base repo which was missing in mobify pelican fork

John Boxall johnboxall merged commit 2dbe03f into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 2 authors.

Apr 08, 2013
Donniel Thomas donnielrt Copied over pelican summary plugin from base repo which was missing i…
…n mobify pelican fork
a9acbf1
Apr 09, 2013
John Boxall johnboxall Allow empty summaries. d1dbe80
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 67 additions and 0 deletions. Show diff stats Hide diff stats

  1. +67 0 pelican/plugins/summary.py
67 pelican/plugins/summary.py
... ... @@ -0,0 +1,67 @@
  1 +"""
  2 +Slightly customized summary plugin that allows for empty summaries.
  3 +
  4 +"""
  5 +import types
  6 +
  7 +from pelican import signals
  8 +
  9 +def initialized(pelican):
  10 + from pelican.settings import _DEFAULT_CONFIG
  11 + _DEFAULT_CONFIG.setdefault('SUMMARY_BEGIN_MARKER',
  12 + '<!-- PELICAN_BEGIN_SUMMARY -->')
  13 + _DEFAULT_CONFIG.setdefault('SUMMARY_END_MARKER',
  14 + '<!-- PELICAN_END_SUMMARY -->')
  15 + if pelican:
  16 + pelican.settings.setdefault('SUMMARY_BEGIN_MARKER',
  17 + '<!-- PELICAN_BEGIN_SUMMARY -->')
  18 + pelican.settings.setdefault('SUMMARY_END_MARKER',
  19 + '<!-- PELICAN_END_SUMMARY -->')
  20 +
  21 +def content_object_init(self_class, instance):
  22 + # If summary is already specified, use it.
  23 + if 'summary' in instance.metadata:
  24 + return
  25 +
  26 + # Override `_get_content` to remove summary markers.
  27 + def _get_content(self):
  28 + content = self._content
  29 + if self.settings['SUMMARY_BEGIN_MARKER']:
  30 + content = content.replace(
  31 + self.settings['SUMMARY_BEGIN_MARKER'], '', 1)
  32 + if self.settings['SUMMARY_END_MARKER']:
  33 + content = content.replace(
  34 + self.settings['SUMMARY_END_MARKER'], '', 1)
  35 + return content
  36 + instance._get_content = types.MethodType(_get_content, instance)
  37 +
  38 + content = instance._content
  39 + if hasattr(instance, '_summary') or content is None:
  40 + return
  41 +
  42 + # The the summary.
  43 + start = -1
  44 + end = -1
  45 +
  46 + if instance.settings['SUMMARY_BEGIN_MARKER']:
  47 + start = content.find(instance.settings['SUMMARY_BEGIN_MARKER'])
  48 +
  49 + if instance.settings['SUMMARY_END_MARKER']:
  50 + end = content.find(instance.settings['SUMMARY_END_MARKER'])
  51 +
  52 + if start != -1 or end != -1:
  53 + # the beginning position has to take into account the length
  54 + # of the marker
  55 + start = (start + len(instance.settings['SUMMARY_BEGIN_MARKER']) if start != -1 else 0)
  56 + end = end if end != -1 else None
  57 + instance._summary = content[start:end]
  58 +
  59 + # Set an empty summary so templates can detect whether one was explictly set.
  60 + # @jb: We can't use `None` here as something throws an error later on.
  61 + else:
  62 + instance._summary = ""
  63 +
  64 +
  65 +def register():
  66 + signals.initialized.connect(initialized)
  67 + signals.content_object_init.connect(content_object_init)

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.