import plugins from core and restructure repo

This commit is contained in:
Deniz Turgut
2013-04-10 19:12:31 -04:00
parent 66e83158ba
commit 9e70c17839
135 changed files with 2628 additions and 204 deletions

27
summary/Readme.rst Normal file
View File

@@ -0,0 +1,27 @@
Summary
-------
This plugin allows easy, variable length summaries directly embedded into the
body of your articles. It introduces two new settings: ``SUMMARY_BEGIN_MARKER``
and ``SUMMARY_END_MARKER``: strings which can be placed directly into an article
to mark the beginning and end of a summary. When found, the standard
``SUMMARY_MAX_LENGTH`` setting will be ignored. The markers themselves will also
be removed from your articles before they are published. The default values
are ``<!-- PELICAN_BEGIN_SUMMARY -->`` and ``<!-- PELICAN_END_SUMMARY -->``.
For example::
Title: My super title
Date: 2010-12-03 10:20
Tags: thats, awesome
Category: yeah
Slug: my-super-post
Author: Alexis Metaireau
This is the content of my super blog post.
<!-- PELICAN_END_SUMMARY -->
and this content occurs after the summary.
Here, the summary is taken to be the first line of the post. Because no
beginning marker was found, it starts at the top of the body. It is possible
to leave out the end marker instead, in which case the summary will start at the
beginning marker and continue to the end of the body.

1
summary/__init__.py Normal file
View File

@@ -0,0 +1 @@
from .summary import *

61
summary/summary.py Normal file
View File

@@ -0,0 +1,61 @@
"""
Summary
-------
This plugin allows easy, variable length summaries directly embedded into the
body of your articles.
"""
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(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)