Skip to content

Commit

Permalink
fix: don't match if file content does not include metadata syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
yndx-birman committed Dec 22, 2021
1 parent e9c5f83 commit bd61004
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/services/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ async function getContentWithUpdatedDynamicMetadata(
}

function matchMetadata(fileContent: string) {
if (!fileContent.startsWith('---')) {
return null;
}

// Search by format:
// ---
// metaName1: metaValue1
Expand Down
14 changes: 10 additions & 4 deletions tests/mocks/include-toc/test2/expected-output/fileA.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
---
---
title: File A
description: YFM description
sourcePath: folder/fileA.md
---
description: YFM description
sourcePath: folder/fileA.md
---

# File A

---

Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

---
8 changes: 5 additions & 3 deletions tests/mocks/include-toc/test2/expected-output/fileB.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
sourcePath: folder/fileB.md
---
---
sourcePath: folder/fileB.md
---
# File B

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

---

Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

---
6 changes: 6 additions & 0 deletions tests/mocks/include-toc/test2/expected-output/folder/fileA.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ title: File A
description: YFM description
---
# File A

---

Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

---
2 changes: 2 additions & 0 deletions tests/mocks/include-toc/test2/expected-output/folder/fileB.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

---

Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

---
6 changes: 6 additions & 0 deletions tests/mocks/include-toc/test2/input/folder/fileA.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ title: File A
description: {{product}} description
---
# File A

---

Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

---
2 changes: 2 additions & 0 deletions tests/mocks/include-toc/test2/input/folder/fileB.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

---

Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

---

0 comments on commit bd61004

Please sign in to comment.