From 99ee27bd35e5d3491d5b9ea77812d4289a72e1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Sat, 17 Aug 2013 12:51:38 +0200 Subject: [PATCH] Add a touch plugin --- touch/README.rst | 7 +++++++ touch/__init__.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 touch/README.rst create mode 100644 touch/__init__.py 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)