__init__.py 736 B

1234567891011121314151617181920212223242526272829303132
  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 register():
  21. signals.content_written.connect(touch_file)