forked from github/pelican
implemented github activity plugin
This commit is contained in:
parent
28c0644eb6
commit
c6c0ee76c2
3 changed files with 40 additions and 0 deletions
27
pelican/plugins/github_activity.py
Normal file
27
pelican/plugins/github_activity.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from pelican import signals
|
||||
from pelican.utils import singleton
|
||||
|
||||
@singleton
|
||||
class GitHubActivity():
|
||||
def __init__(self, generator):
|
||||
try:
|
||||
import feedparser
|
||||
self.ga = feedparser.parse(
|
||||
generator.settings['GITHUB_ACTIVITY_FEED'])
|
||||
except ImportError:
|
||||
raise Exception("unable to find feedparser")
|
||||
|
||||
def fetch(self):
|
||||
return [activity['content'][0]['value'].strip()
|
||||
for activity in self.ga['entries']]
|
||||
|
||||
def add_github_activity(generator, metadata):
|
||||
if 'GITHUB_ACTIVITY_FEED' in generator.settings.keys():
|
||||
|
||||
ga = GitHubActivity(generator)
|
||||
|
||||
ga_html_snippets = ga.fetch()
|
||||
generator.context['github_activity'] = ga_html_snippets
|
||||
|
||||
def register():
|
||||
signals.article_generate_context.connect(add_github_activity)
|
||||
|
|
@ -2,3 +2,4 @@ from blinker import signal
|
|||
|
||||
initialized = signal('pelican_initialized')
|
||||
article_generate_context = signal('article_generate_context')
|
||||
github_activity = signal('github_activity')
|
||||
|
|
|
|||
|
|
@ -222,3 +222,15 @@ def files_changed(path, extensions):
|
|||
LAST_MTIME = mtime
|
||||
return True
|
||||
return False
|
||||
|
||||
def singleton(cls):
|
||||
"""
|
||||
Singleton decorator for multiple calls inside plugins
|
||||
for an example see pelican/plugins/github_activity.py
|
||||
"""
|
||||
instances = {}
|
||||
def getinstance(*args, **kwargs):
|
||||
if cls not in instances:
|
||||
instances[cls] = cls(*args, **kwargs)
|
||||
return instances[cls]
|
||||
return getinstance
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue