diff --git a/touch/README.rst b/touch/README.rst new file mode 100644 index 0000000..09c037d --- /dev/null +++ b/touch/README.rst @@ -0,0 +1,7 @@ +Touch plugin +############ + +A simple plugin doing a touch on your generated files using the date metadata +from the content. + +This helps, into other things, to have the web server gently manage the cache. diff --git a/touch/__init__.py b/touch/__init__.py new file mode 100644 index 0000000..5641473 --- /dev/null +++ b/touch/__init__.py @@ -0,0 +1,20 @@ +from pelican import signals + +import logging +import os +import time + + +logger = logging.getLogger(__name__) + + +def touch_file(path, context): + content = context.get('article', context.get('page')) + if content and hasattr(content, 'date'): + mtime = time.mktime(content.date.timetuple()) + logger.info('touching %s', path) + os.utime(path, (mtime, mtime)) + + +def register(): + signals.content_written.connect(touch_file)