diff --git a/docs/plugins.rst b/docs/plugins.rst index 6763f5ef..42ecd656 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -52,12 +52,13 @@ List of signals Here is the list of currently implemented signals: -========================= ============================ ===================== +========================= ============================ ========================================= Signal Arguments Description -========================= ============================ ===================== +========================= ============================ ========================================= initialized pelican object article_generate_context article_generator, metadata -========================= ============================ ===================== +article_generator_init article_generator invoked in the ArticlesGenerator.__init__ +========================= ============================ ========================================= The list is currently small, don't hesitate to add signals and make a pull request if you need them! @@ -73,3 +74,41 @@ Tag cloud Translation ----------- + +Github Activity +_______________ + +This plugins introduces a new depencency, you have to install feedparser +if you want to use it, these are some ways to do it:: + + apt-get install python-feedparser # on debian based distributions like ubuntu + sudo easy_install feedparser + sudo pip install feedparser + +To enable it set in your pelican config file the GITHUB_ACTIVITY_FEED +parameter pointing to your github activity feed. + +for example my personal activity feed is:: + + https://github.com/kpanic.atom + +and the config line could be:: + + GITHUB_ACTIVITY_FEED = 'https://github.com/kpanic.atom' + +in your template just write a for in jinja2 syntax against the +github_activity variable, like for example:: + + {% if GITHUB_ACTIVITY_FEED %} +
+

Github Activity

+ {% for activity in github_activity %} + {{ activity }} + {% endfor %} +
+ {% endif %} + + +github_activity is a list containing raw html from github so you can include it +directly in your (for example base.html) template and style it in a way that +your prefer using your css skills diff --git a/pelican/generators.py b/pelican/generators.py index 38fa9da7..9baf240e 100755 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -101,6 +101,7 @@ class ArticlesGenerator(Generator): self.categories = defaultdict(list) super(ArticlesGenerator, self).__init__(*args, **kwargs) self.drafts = [] + signals.article_generator_init.send(self) def generate_feeds(self, writer): """Generate the feeds from the current context, and output files.""" diff --git a/pelican/plugins/github_activity.py b/pelican/plugins/github_activity.py new file mode 100644 index 00000000..ba6cd70f --- /dev/null +++ b/pelican/plugins/github_activity.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +""" + Copyright (c) Marco Milanesi + + A plugin to list your Github Activity + To enable it set in your pelican config file the GITHUB_ACTIVITY_FEED + parameter pointing to your github activity feed. + + for example my personal activity feed is: + + https://github.com/kpanic.atom + + in your template just write a for in jinja2 syntax against the + github_activity variable. + + github_activity is a list containing raw html from github so you can + include it directly in your template + +""" + +from pelican import signals + + +class GitHubActivity(): + """ + A class created to fetch github activity with feedparser + """ + def __init__(self, generator): + try: + import feedparser + self.activities = feedparser.parse( + generator.settings['GITHUB_ACTIVITY_FEED']) + except ImportError: + raise Exception("unable to find feedparser") + + def fetch(self): + """ + returns a list of html snippets fetched from github actitivy feed + """ + return [activity['content'][0]['value'].strip() + for activity in self.activities['entries']] + + +def fetch_github_activity(gen, metadata): + """ + registered handler for the github activity plugin + it puts in generator.context the html needed to be displayed on a + template + """ + + if 'GITHUB_ACTIVITY_FEED' in gen.settings.keys(): + gen.context['github_activity'] = gen.plugin_instance.fetch() + + +def feed_parser_initialization(generator): + """ + Initialization of feed parser + """ + + generator.plugin_instance = GitHubActivity(generator) + + +def register(): + """ + Plugin registration + """ + signals.article_generator_init.connect(feed_parser_initialization) + signals.article_generate_context.connect(fetch_github_activity) diff --git a/pelican/signals.py b/pelican/signals.py index f2bf4547..b1c35794 100644 --- a/pelican/signals.py +++ b/pelican/signals.py @@ -2,3 +2,4 @@ from blinker import signal initialized = signal('pelican_initialized') article_generate_context = signal('article_generate_context') +article_generator_init = signal('article_generator_init')