gravatar.py 853 B

1234567891011121314151617181920212223242526272829303132
  1. """
  2. Gravatar plugin for Pelican
  3. ===========================
  4. This plugin assigns the ``author_gravatar`` variable to the Gravatar URL and
  5. makes the variable available within the article's context.
  6. """
  7. import hashlib
  8. import six
  9. from pelican import signals
  10. def add_gravatar(generator, metadata):
  11. #first check email
  12. if 'email' not in metadata.keys()\
  13. and 'AUTHOR_EMAIL' in generator.settings.keys():
  14. metadata['email'] = generator.settings['AUTHOR_EMAIL']
  15. #then add gravatar url
  16. if 'email' in metadata.keys():
  17. email_bytes = six.b(metadata['email']).lower()
  18. gravatar_url = "http://www.gravatar.com/avatar/" + \
  19. hashlib.md5(email_bytes).hexdigest()
  20. metadata["author_gravatar"] = gravatar_url
  21. def register():
  22. signals.article_generate_context.connect(add_gravatar)