Add a touch plugin
This commit is contained in:
7
touch/README.rst
Normal file
7
touch/README.rst
Normal 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
20
touch/__init__.py
Normal 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)
|
||||||
Reference in New Issue
Block a user