members.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """
  2. Members info plugin for Pelican
  3. ===============================
  4. This plugin looks for a ``members`` metadata header containing key/value pairs
  5. and makes them available for use in templates
  6. The first line of the members metadata defines each key, and the following
  7. lines contain corresponding values for each member.
  8. :members: nome, email, twitter, github, site_nome, site_href
  9. Danilo Shiga, daniloshiga@gmail.com, @daneoshiga, daneoshiga, Danilo Shiga, http://daniloshiga.com
  10. """
  11. from collections import OrderedDict
  12. from pelican import signals
  13. def add_members(generator, metadata):
  14. if 'members' in metadata.keys():
  15. # Dealing with differences on metadata for md and rst content
  16. if type(metadata['members']) == list:
  17. members = metadata['members']
  18. else:
  19. members = metadata['members'].splitlines()
  20. metadata['members'] = OrderedDict()
  21. keys = map(unicode.strip, members[0].split(','))
  22. for member in members[1:]:
  23. values = map(unicode.strip, member.split(','))
  24. member_dict = dict(zip(keys, values))
  25. metadata['members'][member_dict['nome']] = member_dict
  26. def register():
  27. signals.page_generator_context.connect(add_members)