Skip to content

Commit f0fe09c

Browse files
committed
Cleanup YAML frontmatter parser code.
1 parent a0b220e commit f0fe09c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/formats/frontmatter.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ const parsers = {
1616
}
1717
return jsonFormatter.fromFile(JSONinput);
1818
},
19-
yaml: input => yamlFormatter.fromFile(input),
19+
yaml: {
20+
parse: input => yamlFormatter.fromFile(input),
21+
stringify: (metadata, { sortedKeys }) => yamlFormatter.toFile(metadata, sortedKeys),
22+
},
2023
}
2124

2225
function inferFrontmatterFormat(str) {
@@ -50,11 +53,7 @@ export default {
5053
const { body, ...meta } = data;
5154

5255
// always stringify to YAML
53-
const parser = {
54-
stringify(metadata) {
55-
return yamlFormatter.toFile(metadata, sortedKeys);
56-
},
57-
};
58-
return matter.stringify(body, meta, { language: "yaml", delimiters: "---", engines: { yaml: parser } });
56+
// `sortedKeys` is not recognized by gray-matter, so it gets passed through to the parser
57+
return matter.stringify(body, meta, { engines: parsers, language: "yaml", delimiters: "---", sortedKeys });
5958
}
6059
}

0 commit comments

Comments
 (0)