Switch back to gray-matter
for front-matter parsing.
This commit is contained in:
parent
ab8226ce63
commit
ebf91a9800
@ -106,6 +106,7 @@
|
|||||||
"dateformat": "^1.0.12",
|
"dateformat": "^1.0.12",
|
||||||
"deep-equal": "^1.0.1",
|
"deep-equal": "^1.0.1",
|
||||||
"fuzzy": "^0.1.1",
|
"fuzzy": "^0.1.1",
|
||||||
|
"gray-matter": "^3.0.3",
|
||||||
"history": "^2.1.2",
|
"history": "^2.1.2",
|
||||||
"immutability-helper": "^2.0.0",
|
"immutability-helper": "^2.0.0",
|
||||||
"immutable": "^3.7.6",
|
"immutable": "^3.7.6",
|
||||||
@ -121,9 +122,6 @@
|
|||||||
"moment": "^2.11.2",
|
"moment": "^2.11.2",
|
||||||
"node-sass": "^3.10.0",
|
"node-sass": "^3.10.0",
|
||||||
"normalize.css": "^4.2.0",
|
"normalize.css": "^4.2.0",
|
||||||
"preliminaries": "^1.3.0",
|
|
||||||
"preliminaries-parser-toml": "^1.3.0",
|
|
||||||
"preliminaries-parser-yaml": "^1.3.0",
|
|
||||||
"prismjs": "^1.5.1",
|
"prismjs": "^1.5.1",
|
||||||
"prop-types": "^15.5.10",
|
"prop-types": "^15.5.10",
|
||||||
"react": "^15.1.0",
|
"react": "^15.1.0",
|
||||||
@ -164,6 +162,7 @@
|
|||||||
"slate-edit-table": "^0.10.1",
|
"slate-edit-table": "^0.10.1",
|
||||||
"slate-soft-break": "^0.3.0",
|
"slate-soft-break": "^0.3.0",
|
||||||
"slug": "^0.9.1",
|
"slug": "^0.9.1",
|
||||||
|
"toml": "^2.3.3",
|
||||||
"unified": "^6.1.4",
|
"unified": "^6.1.4",
|
||||||
"unist-builder": "^1.0.2",
|
"unist-builder": "^1.0.2",
|
||||||
"unist-util-visit-parents": "^1.1.1",
|
"unist-util-visit-parents": "^1.1.1",
|
||||||
|
@ -1,28 +1,22 @@
|
|||||||
import preliminaries from 'preliminaries';
|
import matter from 'gray-matter';
|
||||||
import yamlParser from 'preliminaries-parser-yaml';
|
import tomlEng from 'toml';
|
||||||
import tomlParser from 'preliminaries-parser-toml';
|
|
||||||
import YAML from './yaml';
|
import YAML from './yaml';
|
||||||
|
|
||||||
// Automatically register parsers
|
|
||||||
preliminaries(true);
|
|
||||||
yamlParser(true);
|
|
||||||
tomlParser(true);
|
|
||||||
|
|
||||||
function inferFrontmatterFormat(str) {
|
function inferFrontmatterFormat(str) {
|
||||||
const firstLine = str.substr(0, str.indexOf('\n')).trim();
|
const firstLine = str.substr(0, str.indexOf('\n')).trim();
|
||||||
switch (firstLine) {
|
switch (firstLine) {
|
||||||
case "---":
|
case "---":
|
||||||
return { lang: "yaml", delims: "---" };
|
return { language: "yaml", delimiters: "---" };
|
||||||
case "+++":
|
case "+++":
|
||||||
return { lang: "toml", delims: "+++" };
|
return { language: "toml", delimiters: "+++", engines: { toml: tomlEng.parse.bind(tomlEng) } };
|
||||||
case "{":
|
case "{":
|
||||||
return { lang: "json", delims: ["{", "}"] };
|
return { language: "json", delimiters: ["{", "}"] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Frontmatter {
|
export default class Frontmatter {
|
||||||
fromFile(content) {
|
fromFile(content) {
|
||||||
const result = preliminaries.parse(content, inferFrontmatterFormat(content));
|
const result = matter(content, inferFrontmatterFormat(content));
|
||||||
const data = result.data;
|
const data = result.data;
|
||||||
data.body = result.content;
|
data.body = result.content;
|
||||||
return data;
|
return data;
|
||||||
@ -45,6 +39,6 @@ export default class Frontmatter {
|
|||||||
return new YAML().toFile(metadata, sortedKeys);
|
return new YAML().toFile(metadata, sortedKeys);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
return preliminaries.stringify(body, meta, { lang: "yaml", delims: "---", parser });
|
return matter.stringify(body, meta, { language: "yaml", delimiters: "---", engines: { yaml: parser } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
yarn.lock
39
yarn.lock
@ -3513,6 +3513,14 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4:
|
|||||||
version "4.1.11"
|
version "4.1.11"
|
||||||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
|
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
|
||||||
|
|
||||||
|
gray-matter@^3.0.3:
|
||||||
|
version "3.0.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/gray-matter/-/gray-matter-3.0.3.tgz#0451a7eacdcb4f13fcbe12b14725422bc86b1030"
|
||||||
|
dependencies:
|
||||||
|
js-yaml "^3.8.1"
|
||||||
|
kind-of "^5.0.0"
|
||||||
|
strip-bom-string "^1.0.0"
|
||||||
|
|
||||||
growly@^1.3.0:
|
growly@^1.3.0:
|
||||||
version "1.3.0"
|
version "1.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
|
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
|
||||||
@ -4809,6 +4817,10 @@ kind-of@^4.0.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
is-buffer "^1.1.5"
|
is-buffer "^1.1.5"
|
||||||
|
|
||||||
|
kind-of@^5.0.0:
|
||||||
|
version "5.0.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-5.0.2.tgz#f57bec933d9a2209ffa96c5c08343607b7035fda"
|
||||||
|
|
||||||
known-css-properties@^0.2.0:
|
known-css-properties@^0.2.0:
|
||||||
version "0.2.0"
|
version "0.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/known-css-properties/-/known-css-properties-0.2.0.tgz#899c94be368e55b42d7db8d5be7d73a4a4a41454"
|
resolved "https://registry.yarnpkg.com/known-css-properties/-/known-css-properties-0.2.0.tgz#899c94be368e55b42d7db8d5be7d73a4a4a41454"
|
||||||
@ -6754,23 +6766,6 @@ postcss@^6.0.1, postcss@^6.0.2:
|
|||||||
source-map "^0.5.6"
|
source-map "^0.5.6"
|
||||||
supports-color "^4.2.1"
|
supports-color "^4.2.1"
|
||||||
|
|
||||||
preliminaries-parser-toml@^1.3.0:
|
|
||||||
version "1.3.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/preliminaries-parser-toml/-/preliminaries-parser-toml-1.3.0.tgz#e62203c45d1c5bf5908b02fb8830336b59a0ebe6"
|
|
||||||
dependencies:
|
|
||||||
toml "^2.3.2"
|
|
||||||
toml-js "0.0.8"
|
|
||||||
|
|
||||||
preliminaries-parser-yaml@^1.3.0:
|
|
||||||
version "1.3.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/preliminaries-parser-yaml/-/preliminaries-parser-yaml-1.3.0.tgz#72b5c69c930e322b07ed78a6696d4bf61de73585"
|
|
||||||
dependencies:
|
|
||||||
js-yaml "^3.8.1"
|
|
||||||
|
|
||||||
preliminaries@^1.3.0:
|
|
||||||
version "1.3.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/preliminaries/-/preliminaries-1.3.0.tgz#da1602e704c36da5dde59b7f4aea2a5380ee6357"
|
|
||||||
|
|
||||||
prelude-ls@~1.1.2:
|
prelude-ls@~1.1.2:
|
||||||
version "1.1.2"
|
version "1.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
|
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
|
||||||
@ -8257,6 +8252,10 @@ strip-ansi@^4.0.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
ansi-regex "^3.0.0"
|
ansi-regex "^3.0.0"
|
||||||
|
|
||||||
|
strip-bom-string@^1.0.0:
|
||||||
|
version "1.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/strip-bom-string/-/strip-bom-string-1.0.0.tgz#e5211e9224369fbb81d633a2f00044dc8cedad92"
|
||||||
|
|
||||||
strip-bom@3.0.0, strip-bom@^3.0.0:
|
strip-bom@3.0.0, strip-bom@^3.0.0:
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
|
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
|
||||||
@ -8651,11 +8650,7 @@ to-fast-properties@^1.0.3:
|
|||||||
version "1.0.3"
|
version "1.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"
|
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"
|
||||||
|
|
||||||
toml-js@0.0.8:
|
toml@^2.3.3:
|
||||||
version "0.0.8"
|
|
||||||
resolved "https://registry.yarnpkg.com/toml-js/-/toml-js-0.0.8.tgz#648ea6f1a4d63b19c0bb30b8ed03e40d09473b0a"
|
|
||||||
|
|
||||||
toml@^2.3.2:
|
|
||||||
version "2.3.3"
|
version "2.3.3"
|
||||||
resolved "https://registry.yarnpkg.com/toml/-/toml-2.3.3.tgz#8d683d729577cb286231dfc7a8affe58d31728fb"
|
resolved "https://registry.yarnpkg.com/toml/-/toml-2.3.3.tgz#8d683d729577cb286231dfc7a8affe58d31728fb"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user