diff --git a/manifest.json b/manifest.json index 94671b9..7ae9fc8 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "frontmatter-generator", "name": "Frontmatter generator", - "version": "1.0.22", + "version": "1.0.23", "minAppVersion": "0.15.0", "description": "Generate frontmatter for your notes from json and javascript", "author": "Hananoshika Yomaru", diff --git a/package.json b/package.json index bb50446..b892493 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-frontmatter-generator", - "version": "1.0.22", + "version": "1.0.23", "description": "A plugin for Obsidian that generates frontmatter for notes.", "main": "main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index 326c450..ad9565a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -181,40 +181,40 @@ export default class FrontmatterGeneratorPlugin extends Plugin { this.app.workspace.on("file-menu", async (menu, file) => { if (file instanceof TFile && isMarkdownFile(file)) { menu.addItem((item) => { - item.setTitle( - "Generate frontmatter for this file" - ).onClick(async () => { - const activeFile = - this.app.workspace.getActiveFile(); - const view = - this.app.workspace.getActiveViewOfType( - MarkdownView - ); - const editor = view?.editor; - const isUsingPropertiesEditor = - view?.getMode() === "source" && - // @ts-ignore - !view.currentMode.sourceMode; - if ( - activeFile === file && - editor && - !isUsingPropertiesEditor - ) { - this.runFileSync(file, editor); - } else if ( - activeFile === file && - editor && - isUsingPropertiesEditor - ) { - await this.runFile(file); - } - }); + item.setIcon("file-cog") + .setTitle("Generate frontmatter for this file") + .onClick(async () => { + const activeFile = + this.app.workspace.getActiveFile(); + const view = + this.app.workspace.getActiveViewOfType( + MarkdownView + ); + const editor = view?.editor; + const isUsingPropertiesEditor = + view?.getMode() === "source" && + // @ts-ignore + !view.currentMode.sourceMode; + if ( + activeFile === file && + editor && + !isUsingPropertiesEditor + ) { + this.runFileSync(file, editor); + } else if ( + activeFile === file && + editor && + isUsingPropertiesEditor + ) { + await this.runFile(file); + } + }); }); } else if (file instanceof TFolder) { menu.addItem((item) => { - item.setTitle( - "Generate frontmatter in this folder" - ).onClick(() => this.runAllFilesInFolder(file)); + item.setIcon("file-cog") + .setTitle("Generate frontmatter in this folder") + .onClick(() => this.runAllFilesInFolder(file)); }); } }) @@ -222,7 +222,6 @@ export default class FrontmatterGeneratorPlugin extends Plugin { this.registerEvent( this.app.vault.on("modify", async (file) => { - console.log("modify", file); if (!this.settings.runOnModify) return; if (this.lock) return; try { diff --git a/src/utils/obsidian.ts b/src/utils/obsidian.ts index 75210da..1ffdbd6 100644 --- a/src/utils/obsidian.ts +++ b/src/utils/obsidian.ts @@ -37,9 +37,18 @@ export function getAllFilesInFolder(startingFolder: TFolder): TFile[] { export const getDataFromTextSync = (text: string) => { const yamlText = getYAMLText(text); + const yamlObj = yamlText + ? (parseYaml(yamlText) as { [x: string]: any }) + : null; + const { body } = splitYamlAndBody(text); - const tags: string[] = []; + const yamlTags = yamlObj?.tags as string | string[] | undefined; + + // if tags is a string, convert it to an array + const _tags = typeof yamlTags === "string" ? [yamlTags] : yamlTags; + + const tags: string[] = _tags ? _tags.map((t) => `#${t}`) : []; ignoreListOfTypes([IgnoreTypes.yaml], text, (text) => { // get all the tags except the generated ones tags.push(...matchTagRegex(text)); @@ -47,12 +56,12 @@ export const getDataFromTextSync = (text: string) => { return text; }); + console.log(tags); + return { text, yamlText, - yamlObj: yamlText - ? (parseYaml(yamlText) as { [x: string]: any }) - : null, + yamlObj, tags, body, }; diff --git a/versions.json b/versions.json index 59c839b..839f046 100644 --- a/versions.json +++ b/versions.json @@ -20,5 +20,6 @@ "1.0.19": "0.15.0", "1.0.20": "0.15.0", "1.0.21": "0.15.0", - "1.0.22": "0.15.0" + "1.0.22": "0.15.0", + "1.0.23": "0.15.0" } \ No newline at end of file