Skip to content

Commit

Permalink
Merge pull request #18 from HiDeoo/hd-fix-embedded-note-frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed May 6, 2024
2 parents 19b2088 + 388a178 commit 8233a76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions fixtures/basics/Embeds.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
foo: bar
baz: true
---

![[An image.png]]

![[A sound.mp3]]
Expand Down
20 changes: 16 additions & 4 deletions packages/starlight-obsidian/libs/remark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ export function remarkStarlightObsidian() {
}
})

if (!file.data.embedded) {
handleFrontmatter(tree, file, obsidianFrontmatter)
}

handleFrontmatter(tree, file, obsidianFrontmatter)
handleImports(tree, file)
}
}
Expand All @@ -101,6 +98,21 @@ function getObsidianFrontmatter(tree: Root) {
}

function handleFrontmatter(tree: Root, file: VFile, obsidianFrontmatter?: ObsidianFrontmatter) {
// Remove the existing frontmatter, if any, for embedded notes.
if (file.data.embedded) {
// The frontmatter is always at the root of the tree.
for (const [index, node] of tree.children.entries()) {
if (node.type !== 'yaml') {
continue
}

tree.children.splice(index, 1)
break
}

return
}

let hasFrontmatter = false

// The frontmatter is always at the root of the tree.
Expand Down

0 comments on commit 8233a76

Please sign in to comment.