1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- """Libravatar plugin for Pelican"""
- import hashlib
- from pelican import signals
- def initialize (pelicanobj):
- """Initialize the Libravatar plugin"""
- pelicanobj.settings.setdefault ('LIBRAVATAR_MISSING', None)
- pelicanobj.settings.setdefault ('LIBRAVATAR_SIZE', None)
- def add_libravatar (generator, metadata):
- """Article generator connector for the Libravatar plugin"""
- missing = generator.settings.get ('LIBRAVATAR_MISSING')
- size = generator.settings.get ('LIBRAVATAR_SIZE')
-
- if 'email' not in metadata.keys ():
- try:
- metadata ['email'] = generator.settings.get ('AUTHOR_EMAIL')
- except:
- pass
-
- if metadata ['email']:
-
-
- email = metadata ['email'].lower ().encode ('ascii')
- md5 = hashlib.md5 (email).hexdigest ()
- url = 'http://cdn.libravatar.org/avatar/' + md5
-
- if missing or size:
- url = url + '?'
- if missing:
- url = url + 'd=' + missing
- if size:
- url = url + '&'
- if size:
- url = url + 's=' + str (size)
-
- metadata ['author_libravatar'] = url
- def register ():
- """Register the Libravatar plugin with Pelican"""
- signals.initialized.connect (initialize)
- signals.article_generator_context.connect (add_libravatar)
|