Skip to content

Commit f82762a

Browse files
authored
fix(cli): markdown files (#540)
1 parent 8f1cfa1 commit f82762a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

.changeset/giant-spoons-carry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
possible fix for loading markdown files

packages/cli/src/cli/loaders/markdown.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export default function createMarkdownLoader(): ILoader<string, Record<string, s
2323

2424
const sections = content
2525
.split(SECTION_REGEX)
26-
.map((section) => section.trim())
26+
.map((section) => section?.trim() ?? "")
2727
.filter(Boolean);
2828

2929
return {
3030
...Object.fromEntries(
3131
sections
32-
.map((section, index) => [`${MD_SECTION_PREFIX}${index}`, section.trim()])
32+
.map((section, index) => [`${MD_SECTION_PREFIX}${index}`, section])
3333
.filter(([, section]) => Boolean(section)),
3434
),
3535
...Object.fromEntries(Object.entries(frontmatter).map(([key, value]) => [`${FM_ATTR_PREFIX}${key}`, value])),
@@ -45,7 +45,7 @@ export default function createMarkdownLoader(): ILoader<string, Record<string, s
4545
let content = Object.entries(data)
4646
.filter(([key]) => key.startsWith(MD_SECTION_PREFIX))
4747
.sort(([a], [b]) => Number(a.split("-").pop()) - Number(b.split("-").pop()))
48-
.map(([, value]) => value.trim())
48+
.map(([, value]) => value?.trim() ?? "")
4949
.filter(Boolean)
5050
.join("\n\n");
5151

0 commit comments

Comments
 (0)