From f0fe09cb7a5ca2d954aeb8570b85d9c310e19c43 Mon Sep 17 00:00:00 2001 From: Caleb Date: Sun, 29 Oct 2017 17:33:44 -0600 Subject: [PATCH] Cleanup YAML frontmatter parser code. --- src/formats/frontmatter.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/formats/frontmatter.js b/src/formats/frontmatter.js index 1696964be3ba..620ee090769e 100644 --- a/src/formats/frontmatter.js +++ b/src/formats/frontmatter.js @@ -16,7 +16,10 @@ const parsers = { } return jsonFormatter.fromFile(JSONinput); }, - yaml: input => yamlFormatter.fromFile(input), + yaml: { + parse: input => yamlFormatter.fromFile(input), + stringify: (metadata, { sortedKeys }) => yamlFormatter.toFile(metadata, sortedKeys), + }, } function inferFrontmatterFormat(str) { @@ -50,11 +53,7 @@ export default { const { body, ...meta } = data; // always stringify to YAML - const parser = { - stringify(metadata) { - return yamlFormatter.toFile(metadata, sortedKeys); - }, - }; - return matter.stringify(body, meta, { language: "yaml", delimiters: "---", engines: { yaml: parser } }); + // `sortedKeys` is not recognized by gray-matter, so it gets passed through to the parser + return matter.stringify(body, meta, { engines: parsers, language: "yaml", delimiters: "---", sortedKeys }); } }