forked from getpelican/pelican-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dateish.py
28 lines (22 loc) · 794 Bytes
/
dateish.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
# -*- coding: utf-8 -*-
"""
Dateish Plugin for Pelican
==========================
This plugin adds the ability to treat arbitrary metadata fields as datetime
objects.
"""
from pelican import signals
from pelican.utils import get_date
def dateish(generator):
if 'DATEISH_PROPERTIES' not in generator.settings:
return
for article in generator.articles:
for field in generator.settings['DATEISH_PROPERTIES']:
if hasattr(article, field):
value = getattr(article, field)
if type(value) == list:
setattr(article, field, [get_date(d) for d in value])
else:
setattr(article, field, get_date(value))
def register():
signals.article_generator_finalized.connect(dateish)