mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #168 from kpanic/plugin-github-activity
Github activity Plugin
This commit is contained in:
commit
d33bd1cad1
4 changed files with 112 additions and 3 deletions
|
|
@ -52,12 +52,13 @@ List of signals
|
||||||
|
|
||||||
Here is the list of currently implemented signals:
|
Here is the list of currently implemented signals:
|
||||||
|
|
||||||
========================= ============================ =====================
|
========================= ============================ =========================================
|
||||||
Signal Arguments Description
|
Signal Arguments Description
|
||||||
========================= ============================ =====================
|
========================= ============================ =========================================
|
||||||
initialized pelican object
|
initialized pelican object
|
||||||
article_generate_context article_generator, metadata
|
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
|
The list is currently small, don't hesitate to add signals and make a pull
|
||||||
request if you need them!
|
request if you need them!
|
||||||
|
|
@ -73,3 +74,41 @@ Tag cloud
|
||||||
|
|
||||||
Translation
|
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 %}
|
||||||
|
<div class="social">
|
||||||
|
<h2>Github Activity</h2>
|
||||||
|
{% for activity in github_activity %}
|
||||||
|
{{ activity }}
|
||||||
|
{% endfor %}
|
||||||
|
</div><!-- /.social -->
|
||||||
|
{% 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
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,7 @@ class ArticlesGenerator(Generator):
|
||||||
self.categories = defaultdict(list)
|
self.categories = defaultdict(list)
|
||||||
super(ArticlesGenerator, self).__init__(*args, **kwargs)
|
super(ArticlesGenerator, self).__init__(*args, **kwargs)
|
||||||
self.drafts = []
|
self.drafts = []
|
||||||
|
signals.article_generator_init.send(self)
|
||||||
|
|
||||||
def generate_feeds(self, writer):
|
def generate_feeds(self, writer):
|
||||||
"""Generate the feeds from the current context, and output files."""
|
"""Generate the feeds from the current context, and output files."""
|
||||||
|
|
|
||||||
68
pelican/plugins/github_activity.py
Normal file
68
pelican/plugins/github_activity.py
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
Copyright (c) Marco Milanesi <kpanic@gnufunk.org>
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
@ -2,3 +2,4 @@ from blinker import signal
|
||||||
|
|
||||||
initialized = signal('pelican_initialized')
|
initialized = signal('pelican_initialized')
|
||||||
article_generate_context = signal('article_generate_context')
|
article_generate_context = signal('article_generate_context')
|
||||||
|
article_generator_init = signal('article_generator_init')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue