diff options
author | Sunaina Pai <sunainapai.in@gmail.com> | 2018-08-11 14:40:18 +0530 |
---|---|---|
committer | Sunaina Pai <sunainapai.in@gmail.com> | 2018-08-11 14:40:18 +0530 |
commit | 8195677cae913e2f964bf631d88f00a33e16bc24 (patch) | |
tree | 3dddc9320f46c48e7b5e43bbbe4fb765b75b4e9b /makesite.py | |
parent | 020ab349067939a121f8b75f003501a7e00198c6 (diff) |
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.
Diffstat (limited to 'makesite.py')
-rwxr-xr-x | makesite.py | 13 |
1 files changed, 10 insertions, 3 deletions
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) |