From 747543ac12a33ccd60ae7c4f68909ca075cd3cec Mon Sep 17 00:00:00 2001 From: Keith Gaughan Date: Sat, 14 Apr 2018 12:47:13 +0100 Subject: Improved, single-pass templating. --- makesite.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/makesite.py b/makesite.py index 25744ea..ce1c9b3 100755 --- a/makesite.py +++ b/makesite.py @@ -112,9 +112,9 @@ def read_content(filename): def render(template, **params): """Replace placeholders in template with values from params.""" - for key, val in params.items(): - template = re.sub(r'{{\s*' + key + '\s*}}', str(val), template) - return template + return re.sub(r'{{\s*([^}\s]+)\s*}}', + lambda match: str(params.get(match.group(1), match.group(0))), + template) def make_pages(src, dst, layout, **params): -- cgit v1.2.3