Skip to content

Commit

Permalink
fix(core): #215 frontmatter parsing on windows
Browse files Browse the repository at this point in the history
Trim the content before it is passed to the yaml parser.
This should fix frontmatter parsing on windows.

Closes: #215
  • Loading branch information
sdorra committed Jul 23, 2024
1 parent 7b24abd commit a1c42c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-games-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@content-collections/core": patch
---

Fix frontmatter parsing in certain situations on Windows.
8 changes: 6 additions & 2 deletions packages/core/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand All @@ -31,6 +35,6 @@ export const parsers = {
},
yaml: {
hasContent: false,
parse,
parse: parseYaml,
},
} as const;

0 comments on commit a1c42c1

Please sign in to comment.