dateish.py 694 B

123456789101112131415161718192021222324252627
  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. text = getattr(article, field)
  17. as_datetime = get_date(text)
  18. setattr(article, field, as_datetime)
  19. def register():
  20. signals.article_generator_finalized.connect(dateish)