-
Notifications
You must be signed in to change notification settings - Fork 3
/
parsers.js
43 lines (40 loc) · 992 Bytes
/
parsers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Default parsers, merged into options. Can be overridden by user options.
*/
import yaml from 'js-yaml';
import marked from 'marked';
import frontMatter from 'front-matter';
var parsers = {
content: {
pattern: '\\.(html|hbs|handlebars)$',
parseFn: (contents, path) => {
var matter = frontMatter(contents);
return {
contents: matter.body,
data: matter.attributes
};
}
},
markdown: {
pattern: '\\.(md|markdown)$',
parseFn: (contents, path) => {
var matter = frontMatter(contents);
return {
contents: marked(matter.body),
data: matter.attributes
};
}
},
yaml: {
pattern: '\\.(yaml|yml)$',
parseFn: (contents, path) => ({ contents: yaml.safeLoad(contents) })
},
json: {
pattern: '\\.json$',
parseFn: (contents, path) => ({ contents: JSON.parse(contents) })
},
default: {
parseFn: (contents, path) => ({ contents: contents })
}
};
export default parsers;