From 990c6f795837b53044174097e643466a19d6c232 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Sat, 6 Jan 2018 19:57:51 -0800 Subject: [PATCH] Added %%current_year%% as template keyword. --- bin/cmless.py | 1 + bin/template.py | 8 +++++++- site_sample/template/template.tpl | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/cmless.py b/bin/cmless.py index 6663cdc..84d5b69 100755 --- a/bin/cmless.py +++ b/bin/cmless.py @@ -15,6 +15,7 @@ def main(): content = misc.load_file(config.site_template_prefix + "/" + config.template_file) content = template.page_title(content) content = template.site_title(content) + content = template.current_year(content) content = template.body(content) print(content) diff --git a/bin/template.py b/bin/template.py index f27f493..a39090f 100644 --- a/bin/template.py +++ b/bin/template.py @@ -2,7 +2,7 @@ # See LICENSE file for copyright and license details. # Python imports -import os +import os, datetime # CMless imports import config, misc @@ -25,3 +25,9 @@ def body(template): body = misc.process_markup(body) return template.replace(config.template_delimiter + keyword + config.template_delimiter, body) + +def current_year(template): + keyword = "current_year" + now = datetime.datetime.now() + return template.replace(config.template_delimiter + keyword + + config.template_delimiter, str(now.year)) diff --git a/site_sample/template/template.tpl b/site_sample/template/template.tpl index 1098ce9..18fcc43 100644 --- a/site_sample/template/template.tpl +++ b/site_sample/template/template.tpl @@ -20,7 +20,7 @@ -- 2.20.1