summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunaina Pai <sunainapai.in@gmail.com>2018-08-11 10:47:51 +0530
committerSunaina Pai <sunainapai.in@gmail.com>2018-08-11 10:47:51 +0530
commitddeb792ecedb4629aa7c8bc33c0eaba45b82b755 (patch)
treeb072ac2b6e7d3663afa85fe44af7171e5141bce1
parent99c8e268a6c2c75943e1069ff95a5d64e1e19908 (diff)
Do not use headers from one post in other posts
-rwxr-xr-xmakesite.py6
-rw-r--r--test/test_pages.py16
2 files changed, 19 insertions, 3 deletions
diff --git a/makesite.py b/makesite.py
index 8f4c736..cf23374 100755
--- a/makesite.py
+++ b/makesite.py
@@ -132,10 +132,10 @@ def make_pages(src, dst, layout, **params):
content = read_content(src_path)
items.append(content)
- params.update(content)
+ page_params = dict(params, **content)
- dst_path = render(dst, **params)
- output = render(layout, **params)
+ dst_path = render(dst, **page_params)
+ output = render(layout, **page_params)
log('Rendering {} => {} ...', src_path, dst_path)
fwrite(dst_path, output)
diff --git a/test/test_pages.py b/test/test_pages.py
index 5fe7a4d..9f52fb7 100644
--- a/test/test_pages.py
+++ b/test/test_pages.py
@@ -18,6 +18,10 @@ class PagesTest(unittest.TestCase):
f.write('Foo')
with open(os.path.join(self.blog_path, '2018-01-02-bar.txt'), 'w') as f:
f.write('Bar')
+ with open(os.path.join(self.blog_path, 'header-foo.txt'), 'w') as f:
+ f.write('<!-- tag: foo -->Foo')
+ with open(os.path.join(self.blog_path, 'header-bar.txt'), 'w') as f:
+ f.write('<!-- title: bar -->Bar')
def tearDown(self):
shutil.rmtree(self.blog_path)
@@ -61,3 +65,15 @@ class PagesTest(unittest.TestCase):
self.assertEqual(len(posts), 2)
self.assertEqual(posts[0]['date'], '2018-01-02')
self.assertEqual(posts[1]['date'], '2018-01-01')
+
+ def test_content_header_params(self):
+ # Test that header params from one post is not used in another
+ # post.
+ src = os.path.join(self.blog_path, 'header*.txt')
+ dst = os.path.join(self.site_path, '{{ slug }}.txt')
+ tpl = '{{ title }}:{{ tag }}:{{ content }}'
+ makesite.make_pages(src, dst, tpl)
+ with open(os.path.join(self.site_path, 'header-foo.txt')) as f:
+ self.assertEqual(f.read(), '{{ title }}:foo:Foo')
+ with open(os.path.join(self.site_path, 'header-bar.txt')) as f:
+ self.assertEqual(f.read(), 'bar:{{ tag }}:Bar')