From 8195677cae913e2f964bf631d88f00a33e16bc24 Mon Sep 17 00:00:00 2001 From: Sunaina Pai Date: Sat, 11 Aug 2018 14:40:18 +0530 Subject: Populate placeholders in content when specified Placeholders in content files are not populated by default. If placeholders are to be populated in content files, parameter named `render` with a string value of `yes` must be specified. This `render` parameter may be specified as a header in content files or it may be specified as a keyword argument in `make_pages` call. --- makesite.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'makesite.py') diff --git a/makesite.py b/makesite.py index cf23374..f4dcf0f 100755 --- a/makesite.py +++ b/makesite.py @@ -107,10 +107,9 @@ def read_content(filename): except ImportError as e: log('WARNING: Cannot render Markdown in {}: {}', filename, str(e)) - # Update the dictionary with content, summary, and RFC 2822 date. + # Update the dictionary with content and RFC 2822 date. content.update({ 'content': text, - 'summary': truncate(text), 'rfc_2822_date': rfc_2822_format(content['date']) }) @@ -130,10 +129,17 @@ def make_pages(src, dst, layout, **params): for src_path in glob.glob(src): content = read_content(src_path) - items.append(content) page_params = dict(params, **content) + # Populate placeholders in content if content-rendering is enabled. + if page_params.get('render') == 'yes': + rendered_content = render(page_params['content'], **page_params) + page_params['content'] = rendered_content + content['content'] = rendered_content + + items.append(content) + dst_path = render(dst, **page_params) output = render(layout, **page_params) @@ -148,6 +154,7 @@ def make_list(posts, dst, list_layout, item_layout, **params): items = [] for post in posts: item_params = dict(params, **post) + item_params['summary'] = truncate(post['content']) item = render(item_layout, **item_params) items.append(item) -- cgit v1.2.3