Skip to content

Commit

Permalink
Cleanup YAML frontmatter parser code.
Browse files Browse the repository at this point in the history
  • Loading branch information
tech4him1 committed Oct 30, 2017
1 parent a0b220e commit f0fe09c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/formats/frontmatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 });
}
}

0 comments on commit f0fe09c

Please sign in to comment.