Skip to content

Commit e7f87c4

Browse files
committed
Use same parsers for files and frontmatter.
We want to use our file parsers for frontmatter, instead of the builtin ones, as they process some formats (images, dates) properly.
1 parent aad6045 commit e7f87c4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/formats/frontmatter.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import matter from 'gray-matter';
22
import tomlFormatter from './toml';
33
import yamlFormatter from './yaml';
4+
import jsonFormatter from './json';
45

56
const parsers = {
67
toml: input => tomlFormatter.fromFile(null, input),
7-
json: (input) => {
8+
json: input => {
89
let JSONinput = input.trim();
910
// Fix JSON if leading and trailing brackets were trimmed.
1011
if (JSONinput.substr(0, 1) !== '{') {
@@ -13,8 +14,9 @@ const parsers = {
1314
if (JSONinput.substr(-1) !== '}') {
1415
JSONinput = JSONinput + '}';
1516
}
16-
return matter.engines.json.parse(JSONinput);
17+
return jsonFormatter.fromFile(null, JSONinput);
1718
},
19+
yaml: input => yamlFormatter.fromFile(null, input),
1820
}
1921

2022
function inferFrontmatterFormat(str) {

0 commit comments

Comments
 (0)