Skip to content

Commit

Permalink
Stop sorting frontmatter keys
Browse files Browse the repository at this point in the history
  • Loading branch information
chezou committed Jan 15, 2022
1 parent 2873743 commit ac77308
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion prelims/post.py
Expand Up @@ -52,7 +52,8 @@ def save(self):
content = self.raw_content.replace(
m.group(1),
yaml.dump(self.front_matter, allow_unicode=True,
default_flow_style=flow_style)
default_flow_style=flow_style,
sort_keys=False)
)
f.write(content)

Expand Down
6 changes: 4 additions & 2 deletions prelims/tests/test_post.py
Expand Up @@ -8,6 +8,7 @@
content = """
---
aaa: xxx
ccc: xxx
bbb: [xxx]
---
Expand Down Expand Up @@ -50,7 +51,7 @@ def tearDown(self):
def test_load(self):
post = Post.load(self.mdfile.name, "utf-8")
self.assertEqual(post.path, self.mdfile.name)
self.assertEqual(post.front_matter, {'aaa': 'xxx', 'bbb': ['xxx']})
self.assertEqual(post.front_matter, {'aaa': 'xxx', 'ccc': 'xxx', 'bbb': ['xxx']})
self.assertEqual(post.raw_content, content)
self.assertEqual(post.content, 'Hello world.')

Expand All @@ -75,7 +76,7 @@ def test_update(self):

self.assertEqual(post.path, self.mdfile.name)
self.assertEqual(post.front_matter,
{'aaa': 'xxx', 'bbb': ['zzz'], 'foo': 'bar'})
{'aaa': 'xxx', 'ccc': 'xxx', 'bbb': ['zzz'], 'foo': 'bar'})

def test_save(self):
post = Post.load(self.mdfile.name, "utf-8")
Expand All @@ -85,6 +86,7 @@ def test_save(self):
expected_content = """
---
aaa: xxx
ccc: xxx
bbb: [xxx]
foo: bar
---
Expand Down

0 comments on commit ac77308

Please sign in to comment.