1
0
Fork 0
forked from github/pelican
pelican-theme/pelican/plugins/gravatar.py

42 lines
1.1 KiB
Python
Raw Normal View History

import hashlib
2011-06-18 01:03:53 +02:00
from pelican import signals
2011-04-26 19:44:55 +02:00
"""
2012-03-21 00:09:44 +01:00
Gravatar plugin for Pelican
===========================
This plugin assigns the ``author_gravatar`` variable to the Gravatar URL and
makes the variable available within the article's context.
2011-04-26 19:44:55 +02:00
Settings:
---------
Add AUTHOR_EMAIL to your settings file to define the default author's email
address. Obviously, that email address must be associated with a Gravatar
account.
2011-04-26 19:44:55 +02:00
Article metadata:
2011-04-26 19:44:55 +02:00
------------------
:email: article's author email
If one of them are defined, the author_gravatar variable is added to the
2011-04-26 19:44:55 +02:00
article's context.
"""
def add_gravatar(generator, metadata):
2012-03-21 00:09:44 +01:00
#first check email
if 'email' not in metadata.keys()\
and 'AUTHOR_EMAIL' in generator.settings.keys():
metadata['email'] = generator.settings['AUTHOR_EMAIL']
2012-03-21 00:09:44 +01:00
#then add gravatar url
if 'email' in metadata.keys():
gravatar_url = "http://www.gravatar.com/avatar/" + \
hashlib.md5(metadata['email'].lower()).hexdigest()
metadata["author_gravatar"] = gravatar_url
2012-03-21 00:09:44 +01:00
def register():
2011-06-18 01:03:53 +02:00
signals.article_generate_context.connect(add_gravatar)