Procházet zdrojové kódy

Merge pull request #63 from getpelican/touch

Add a touch plugin
Kura před 10 roky
rodič
revize
ad00ae460a
2 změnil soubory, kde provedl 27 přidání a 0 odebrání
  1. 7 0
      touch/README.rst
  2. 20 0
      touch/__init__.py

+ 7 - 0
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.

+ 20 - 0
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)