Add a touch plugin

This commit is contained in:
Alexis Métaireau
2013-08-17 12:51:38 +02:00
parent 1b2edca2dd
commit 99ee27bd35
2 changed files with 27 additions and 0 deletions

7
touch/README.rst Normal file
View File

@@ -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
touch/__init__.py Normal file
View File

@@ -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)