__init__.py 884 B

12345678910111213141516171819202122232425262728293031323334353637
  1. from pelican import signals
  2. import logging
  3. import os
  4. import time
  5. logger = logging.getLogger(__name__)
  6. def set_file_utime(path, datetime):
  7. mtime = time.mktime(datetime.timetuple())
  8. logger.info('touching %s', path)
  9. os.utime(path, (mtime, mtime))
  10. def touch_file(path, context):
  11. content = context.get('article', context.get('page'))
  12. page = context.get('articles_page')
  13. dates = context.get('dates')
  14. if content and hasattr(content, 'date'):
  15. set_file_utime(path, content.date)
  16. elif page:
  17. set_file_utime(path, max(x.date for x in page.object_list))
  18. elif dates:
  19. set_file_utime(path, max(x.date for x in dates))
  20. def touch_feed(path, context, feed):
  21. set_file_utime(path, max(x['pubdate'] for x in feed.items))
  22. def register():
  23. signals.content_written.connect(touch_file)
  24. signals.feed_written.connect(touch_feed)