2011-06-18 01:03:53 +02:00
|
|
|
.. _plugins:
|
|
|
|
|
|
|
|
|
|
Plugins
|
|
|
|
|
#######
|
|
|
|
|
|
2012-12-03 16:31:55 -08:00
|
|
|
Beginning with version 3.0, Pelican supports plugins. Plugins are a way to add
|
|
|
|
|
features to Pelican without having to directly modify the Pelican core.
|
2011-06-18 01:03:53 +02:00
|
|
|
|
2012-07-01 10:52:39 -07:00
|
|
|
How to use plugins
|
|
|
|
|
==================
|
2011-06-18 01:03:53 +02:00
|
|
|
|
2012-12-03 16:31:55 -08:00
|
|
|
To load plugins, you have to specify them in your settings file. There are two
|
|
|
|
|
ways to do so. The first method is to specify strings with the path to the
|
|
|
|
|
callables::
|
2011-06-18 01:03:53 +02:00
|
|
|
|
2013-04-12 23:39:39 -04:00
|
|
|
PLUGINS = ['package.myplugin',]
|
2011-06-18 01:03:53 +02:00
|
|
|
|
2012-12-03 16:31:55 -08:00
|
|
|
Alternatively, another method is to import them and add them to the list::
|
2011-06-18 01:03:53 +02:00
|
|
|
|
2013-04-12 23:39:39 -04:00
|
|
|
from package import myplugin
|
|
|
|
|
PLUGINS = [myplugin,]
|
2011-06-18 01:03:53 +02:00
|
|
|
|
2012-07-01 10:52:39 -07:00
|
|
|
If your plugins are not in an importable path, you can specify a ``PLUGIN_PATH``
|
2013-04-05 02:32:58 -04:00
|
|
|
in the settings. ``PLUGIN_PATH`` can be an absolute path or a path relative to
|
|
|
|
|
the settings file::
|
2011-06-18 01:03:53 +02:00
|
|
|
|
|
|
|
|
PLUGIN_PATH = "plugins"
|
|
|
|
|
PLUGINS = ["list", "of", "plugins"]
|
|
|
|
|
|
2013-04-12 23:39:39 -04:00
|
|
|
Where to find plugins
|
|
|
|
|
=====================
|
|
|
|
|
|
2013-04-16 10:13:47 -07:00
|
|
|
We maintain a separate repository of plugins for people to share and use.
|
|
|
|
|
Please visit the `pelican-plugins`_ repository for a list of available plugins.
|
2013-04-12 23:39:39 -04:00
|
|
|
|
|
|
|
|
.. _pelican-plugins: https://github.com/getpelican/pelican-plugins
|
|
|
|
|
|
2013-04-16 10:13:47 -07:00
|
|
|
Please note that while we do our best to review and maintain these plugins,
|
|
|
|
|
they are submitted by the Pelican community and thus may have varying levels of
|
|
|
|
|
support and interoperability.
|
2013-04-12 23:39:39 -04:00
|
|
|
|
2012-07-01 10:52:39 -07:00
|
|
|
How to create plugins
|
|
|
|
|
=====================
|
2011-06-18 01:03:53 +02:00
|
|
|
|
2012-07-01 10:52:39 -07:00
|
|
|
Plugins are based on the concept of signals. Pelican sends signals, and plugins
|
2012-12-03 16:31:55 -08:00
|
|
|
subscribe to those signals. The list of signals are defined in a subsequent
|
2011-06-18 01:03:53 +02:00
|
|
|
section.
|
|
|
|
|
|
2012-07-01 10:52:39 -07:00
|
|
|
The only rule to follow for plugins is to define a ``register`` callable, in
|
|
|
|
|
which you map the signals to your plugin logic. Let's take a simple example::
|
2011-06-18 01:03:53 +02:00
|
|
|
|
|
|
|
|
from pelican import signals
|
|
|
|
|
|
|
|
|
|
def test(sender):
|
|
|
|
|
print "%s initialized !!" % sender
|
|
|
|
|
|
|
|
|
|
def register():
|
|
|
|
|
signals.initialized.connect(test)
|
|
|
|
|
|
|
|
|
|
List of signals
|
|
|
|
|
===============
|
|
|
|
|
|
|
|
|
|
Here is the list of currently implemented signals:
|
|
|
|
|
|
2012-10-13 19:17:16 +02:00
|
|
|
============================= ============================ ===========================================================================
|
|
|
|
|
Signal Arguments Description
|
|
|
|
|
============================= ============================ ===========================================================================
|
|
|
|
|
initialized pelican object
|
|
|
|
|
finalized pelican object invoked after all the generators are executed and just before pelican exits
|
2012-11-06 00:04:45 +01:00
|
|
|
usefull for custom post processing actions, such as:
|
2012-10-13 19:17:16 +02:00
|
|
|
- minifying js/css assets.
|
|
|
|
|
- notify/ping search engines with an updated sitemap.
|
2012-11-20 00:07:44 +01:00
|
|
|
generator_init generator invoked in the Generator.__init__
|
2012-10-13 19:17:16 +02:00
|
|
|
article_generate_context article_generator, metadata
|
2012-11-16 08:09:35 -08:00
|
|
|
article_generate_preread article_generator invoked before a article is read in ArticlesGenerator.generate_context;
|
|
|
|
|
use if code needs to do something before every article is parsed
|
2012-10-13 19:17:16 +02:00
|
|
|
article_generator_init article_generator invoked in the ArticlesGenerator.__init__
|
|
|
|
|
article_generator_finalized article_generator invoked at the end of ArticlesGenerator.generate_context
|
|
|
|
|
get_generators generators invoked in Pelican.get_generator_classes,
|
|
|
|
|
can return a Generator, or several
|
|
|
|
|
generator in a tuple or in a list.
|
2013-01-04 18:19:26 -05:00
|
|
|
page_generate_context page_generator, metadata
|
|
|
|
|
page_generator_init page_generator invoked in the PagesGenerator.__init__
|
|
|
|
|
page_generator_finalized page_generator invoked at the end of PagesGenerator.generate_context
|
2013-04-20 09:08:46 -07:00
|
|
|
content_object_init content_object invoked at the end of Content.__init__ (see note below)
|
2012-10-13 19:17:16 +02:00
|
|
|
============================= ============================ ===========================================================================
|
2011-06-18 01:03:53 +02:00
|
|
|
|
2012-12-03 16:31:55 -08:00
|
|
|
The list is currently small, so don't hesitate to add signals and make a pull
|
2011-06-18 01:03:53 +02:00
|
|
|
request if you need them!
|
|
|
|
|
|
2012-11-06 00:04:45 +01:00
|
|
|
.. note::
|
|
|
|
|
|
2012-12-03 16:31:55 -08:00
|
|
|
The signal ``content_object_init`` can send a different type of object as
|
|
|
|
|
the argument. If you want to register only one type of object then you will
|
2012-09-02 19:20:42 +01:00
|
|
|
need to specify the sender when you are connecting to the signal.
|
2012-11-06 00:04:45 +01:00
|
|
|
|
2012-09-02 19:20:42 +01:00
|
|
|
::
|
2012-11-06 00:04:45 +01:00
|
|
|
|
2012-09-02 19:20:42 +01:00
|
|
|
from pelican import signals
|
|
|
|
|
from pelican import contents
|
2012-11-06 00:04:45 +01:00
|
|
|
|
2012-09-02 19:20:42 +01:00
|
|
|
def test(sender, instance):
|
|
|
|
|
print "%s : %s content initialized !!" % (sender, instance)
|
2012-11-06 00:04:45 +01:00
|
|
|
|
2012-09-02 19:20:42 +01:00
|
|
|
def register():
|
|
|
|
|
signals.content_object_init.connect(test, sender=contents.Article)
|