forked from varia/varia.website
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
855 B
31 lines
855 B
"""
|
|
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.
|
|
"""
|
|
|
|
import hashlib
|
|
import six
|
|
|
|
from pelican import signals
|
|
|
|
|
|
def add_gravatar(generator, metadata):
|
|
|
|
#first check email
|
|
if 'email' not in metadata.keys()\
|
|
and 'AUTHOR_EMAIL' in generator.settings.keys():
|
|
metadata['email'] = generator.settings['AUTHOR_EMAIL']
|
|
|
|
#then add gravatar url
|
|
if 'email' in metadata.keys():
|
|
email_bytes = six.b(metadata['email']).lower()
|
|
gravatar_url = "https://www.gravatar.com/avatar/" + \
|
|
hashlib.md5(email_bytes).hexdigest()
|
|
metadata['author_gravatar'] = gravatar_url
|
|
|
|
|
|
def register():
|
|
signals.article_generator_context.connect(add_gravatar)
|
|
|