3

I am using Pelican 3.3 and I have an almost static file index.html in my jinja2 templates. I would like to display the date of the last modification of the file within it.

I found quite easily that article.locale_date and page.locale_date are doing the job for articles and pages (with DEFAULT_DATE = 'fs'). But, I cannot figure out how to do this for a template file.

I found some suggestions about using a Python function through other Python modules such as Flask or Environment. But, is there a simpler way to get the date of last modification of a template file ?

4

1 回答 1

3

我发现了一个肮脏的把戏,所以我仍然希望有人能以比我更好的方式回答这个问题。

重点是使用pelicanconf.py文件设置环境变量来获取所需的日期。我刚刚将以下内容添加到pelicanconf.py

import os.path, time
INDEX_DATE = time.ctime(os.path.getmtime(path/to/the/index.html))

获得INDEX_DATE变量集后,您可以在 Jinja2 模板中使用它,如下所示:

{{ INDEX_DATE }}

所以,这是一个快速而肮脏的把戏。希望有人会给我更好的方法!

于 2013-12-24T21:13:47.340 回答