Skip to content

Commit

Permalink
[#31,utils/parseFile][s]: obsidian-style tags list support
Browse files Browse the repository at this point in the history
  • Loading branch information
olayway authored Aug 10, 2023
1 parent 2860bd0 commit 14520be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-bikes-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mddb": patch
---

Add support for Obsidian style tags list in frontmatter (e.g. `tags: a,b,c`).
9 changes: 6 additions & 3 deletions src/utils/parseFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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" },
Expand All @@ -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" },
Expand Down
5 changes: 5 additions & 0 deletions src/utils/parseFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down

0 comments on commit 14520be

Please sign in to comment.