dateish.py 794 B

1234567891011121314151617181920212223242526272829
  1. # -*- coding: utf-8 -*-
  2. """
  3. Dateish Plugin for Pelican
  4. ==========================
  5. This plugin adds the ability to treat arbitrary metadata fields as datetime
  6. objects.
  7. """
  8. from pelican import signals
  9. from pelican.utils import get_date
  10. def dateish(generator):
  11. if 'DATEISH_PROPERTIES' not in generator.settings:
  12. return
  13. for article in generator.articles:
  14. for field in generator.settings['DATEISH_PROPERTIES']:
  15. if hasattr(article, field):
  16. value = getattr(article, field)
  17. if type(value) == list:
  18. setattr(article, field, [get_date(d) for d in value])
  19. else:
  20. setattr(article, field, get_date(value))
  21. def register():
  22. signals.article_generator_finalized.connect(dateish)