-
Notifications
You must be signed in to change notification settings - Fork 844
/
Copy path__init__.py
36 lines (24 loc) · 884 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from pelican import signals
import logging
import os
import time
logger = logging.getLogger(__name__)
def set_file_utime(path, datetime):
mtime = time.mktime(datetime.timetuple())
logger.info('touching %s', path)
os.utime(path, (mtime, mtime))
def touch_file(path, context):
content = context.get('article', context.get('page'))
page = context.get('articles_page')
dates = context.get('dates')
if content and hasattr(content, 'date'):
set_file_utime(path, content.date)
elif page:
set_file_utime(path, max(x.date for x in page.object_list))
elif dates:
set_file_utime(path, max(x.date for x in dates))
def touch_feed(path, context, feed):
set_file_utime(path, max(x['pubdate'] for x in feed.items))
def register():
signals.content_written.connect(touch_file)
signals.feed_written.connect(touch_feed)