From a1c42c10fe2081b9a9b6019fce69f9cd99ef3514 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 23 Jul 2024 15:48:45 +0200 Subject: [PATCH] fix(core): #215 frontmatter parsing on windows Trim the content before it is passed to the yaml parser. This should fix frontmatter parsing on windows. Closes: #215 --- .changeset/eleven-games-think.md | 5 +++++ packages/core/src/parser.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/eleven-games-think.md diff --git a/.changeset/eleven-games-think.md b/.changeset/eleven-games-think.md new file mode 100644 index 00000000..6c097e0d --- /dev/null +++ b/.changeset/eleven-games-think.md @@ -0,0 +1,5 @@ +--- +"@content-collections/core": patch +--- + +Fix frontmatter parsing in certain situations on Windows. diff --git a/packages/core/src/parser.ts b/packages/core/src/parser.ts index 814b7e3f..5f449aab 100644 --- a/packages/core/src/parser.ts +++ b/packages/core/src/parser.ts @@ -4,11 +4,15 @@ import { parse, stringify } from "yaml"; export type Parsers = typeof parsers; export type Parser = keyof typeof parsers; +function parseYaml(content: string) { + return parse(content.trim()); +} + function frontmatterParser(fileContent: string) { const { data, content } = matter(fileContent, { engines: { yaml: { - parse, + parse: parseYaml, stringify, }, }, @@ -31,6 +35,6 @@ export const parsers = { }, yaml: { hasContent: false, - parse, + parse: parseYaml, }, } as const;