From 636600f0343e561a138a86affa07f80809822482 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 27 May 2016 15:42:29 +0100 Subject: [PATCH] Add date format template filter --- pelicanconf.py | 7 +++++-- plugins/filters.py | 5 +++++ requirements.txt | 1 + theme/templates/projects.html | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 plugins/filters.py diff --git a/pelicanconf.py b/pelicanconf.py index 4947fd8..85b4263 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -35,8 +35,7 @@ SOCIAL = social.generate() DEFAULT_PAGINATION = False DELETE_OUTPUT_DIRECTORY = True -DEFAULT_DATE_FORMAT = '%c' -DEFAULT_DATE = "fs" + PAGE_PATHS = ["pages"] PAGE_SAVE_AS = "{slug}/index.html" @@ -79,4 +78,8 @@ SITEMAP = { "format": "xml" } +import filters +JINJA_FILTERS = { + "datetime": filters.format_datetime +} # Extra context diff --git a/plugins/filters.py b/plugins/filters.py new file mode 100644 index 0000000..da370a8 --- /dev/null +++ b/plugins/filters.py @@ -0,0 +1,5 @@ +import iso8601 + + +def format_datetime(value): + return iso8601.parse_date(str(value)).strftime("%x") diff --git a/requirements.txt b/requirements.txt index 6edd597..4ddd624 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ colorama==0.3.6 flake8==2.5.0 gitpython==2.0.3 +iso8601==0.1.11 markdown==2.6.6 pelican==3.6.3 diff --git a/theme/templates/projects.html b/theme/templates/projects.html index 30ba848..e12e268 100644 --- a/theme/templates/projects.html +++ b/theme/templates/projects.html @@ -19,7 +19,7 @@

Updated: {{ article.updated }} - Date: {{ article.date }} + Date: {{ article.date|datetime }}

{{ article.content }}