From bd136d5d17f83175b351912849c50a3abc93b078 Mon Sep 17 00:00:00 2001 From: Kacper Kula Date: Sun, 3 Nov 2024 20:43:13 +0000 Subject: [PATCH] feat: fixing issue with tags loading --- src/SealFileSync.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/SealFileSync.ts b/src/SealFileSync.ts index 6053bf1..ffcbbd4 100644 --- a/src/SealFileSync.ts +++ b/src/SealFileSync.ts @@ -1,13 +1,12 @@ -import { App, EventRef, Plugin, TAbstractFile, TFile } from "obsidian"; +import { App, EventRef, getAllTags, Plugin, TAbstractFile, TFile } from "obsidian"; import { SqlSeal } from "./sqlSeal"; import { FieldTypes } from "./utils"; import { TablesManager } from "./dataLoader/collections/tablesManager"; import { sanitise } from "./utils/sanitiseColumn"; -function fileData(file: TAbstractFile, frontmatter: Record) { +function fileData(file: TAbstractFile, {tags: _tags, ...frontmatter }: Record) { return { ...frontmatter, - tags: undefined, path: file.path, name: file.name.replace(/\.[^/.]+$/, ""), id: file.path @@ -131,9 +130,18 @@ export class SealFileSync { } async getFileTags(file: TFile) { - const t = ((this.app.metadataCache.getFileCache(file)?.frontmatter?.tags || []) as string[]) - .map(t => ({ tag: t, fileId: file.path })) - return t + const cache = this.app.metadataCache.getFileCache(file) + if (!cache) { + return [] + } + const tags = getAllTags(cache) + if (!tags) { + return [] + } + return tags.map((t) => ({ + tag: t, + fileId: file.path + })) } async init() {