summaryrefslogtreecommitdiff
path: root/makesite.py
diff options
context:
space:
mode:
authorKeith Gaughan <k@stereochro.me>2018-04-14 12:47:13 +0100
committerKeith Gaughan <k@stereochro.me>2018-04-14 12:47:13 +0100
commit747543ac12a33ccd60ae7c4f68909ca075cd3cec (patch)
treedfeb83938e0478d14d00103af238609e272d79fe /makesite.py
parent8d993d9675dd29719888479178e06dc3ad78c6da (diff)
Improved, single-pass templating.
Diffstat (limited to 'makesite.py')
-rwxr-xr-xmakesite.py6
1 files 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):