Skip to content

Commit

Permalink
Make tags unique at parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsalem401 committed Nov 14, 2023
1 parent 41e1714 commit e2b9d19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/lib/readLocalMarkdownFileToObject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "fs";
import path from "path";
import { getUniqueValues, parseMarkdownContent } from "../utils/index.js";
import { parseMarkdownContent } from "../utils/index.js";
import type { FileObject } from "./types/FileObject.js";
import { MddbFile } from "./schema.js";
import { generateFileIdFromPath } from "../utils/index.js";
Expand Down Expand Up @@ -52,9 +52,8 @@ export function readLocalMarkdownFileToObject(
fileObject.metadata = metadata;
fileObject.filetype = metadata?.type || null;
fileObject.links = links;
const tags = metadata.tags;
if (tags) {
fileObject.tags = getUniqueValues(tags);
if (metadata.tags) {
fileObject.tags = metadata.tags;
}

return fileObject;
Expand Down
7 changes: 6 additions & 1 deletion src/utils/parseMarkdownContent.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import matter from "gray-matter";
import { extractWikiLinks } from "./extractWikiLinks.js";
import { getUniqueValues } from "./getUniqueValues.js";

export function parseMarkdownContent(source: string, options?: { permalinks?: string[] }) {
export function parseMarkdownContent(
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());
metadata.tags = getUniqueValues(metadata.tags);
}

// Links
Expand Down

0 comments on commit e2b9d19

Please sign in to comment.