diff --git a/.changeset/flat-bikes-pull.md b/.changeset/flat-bikes-pull.md new file mode 100644 index 0000000..5f2e315 --- /dev/null +++ b/.changeset/flat-bikes-pull.md @@ -0,0 +1,5 @@ +--- +"mddb": patch +--- + +Add support for Obsidian style tags list in frontmatter (e.g. `tags: a,b,c`). diff --git a/src/utils/parseFile.spec.ts b/src/utils/parseFile.spec.ts index 5541afc..28de0e3 100644 --- a/src/utils/parseFile.spec.ts +++ b/src/utils/parseFile.spec.ts @@ -2,7 +2,8 @@ import { parseFile } from "./parseFile"; const source = `--- title: Hello World -tags: [hello, world] +authors: [John Doe, Jane Doe] +tags: a, b, c --- # Hello World [[Some Link]] @@ -15,7 +16,8 @@ describe("parseFile", () => { it("should parse a file returning metadata and wiki links", () => { const expectedMetadata = { title: "Hello World", - tags: ["hello", "world"], + authors: ["John Doe", "Jane Doe"], + tags: ["a", "b", "c"], }; const expectedLinks = [ { linkType: "normal", linkSrc: "Some Link" }, @@ -31,7 +33,8 @@ describe("parseFile", () => { it("should parse a file returning metadata and wiki links with Obsidian-style shortest paths", () => { const expectedMetadata = { title: "Hello World", - tags: ["hello", "world"], + authors: ["John Doe", "Jane Doe"], + tags: ["a", "b", "c"], }; const expectedLinks = [ { linkType: "normal", linkSrc: "/some/folder/Some Link" }, diff --git a/src/utils/parseFile.ts b/src/utils/parseFile.ts index bb47396..6a2d21a 100644 --- a/src/utils/parseFile.ts +++ b/src/utils/parseFile.ts @@ -5,6 +5,11 @@ export function parseFile(source: string, options?: { permalinks?: string[] }) { // Metadata const { data: metadata } = matter(source); + // Obsidian style tags i.e. tags: tag1, tag2, tag3 + if (metadata.tags && typeof metadata.tags === "string") { + metadata.tags = metadata.tags.split(",").map((tag: string) => tag.trim()); + } + // Links const links = extractWikiLinks(source, { permalinks: options?.permalinks });