diff --git a/src/metaController.ts b/src/metaController.ts index 7d87a80..40d9776 100644 --- a/src/metaController.ts +++ b/src/metaController.ts @@ -314,10 +314,11 @@ export default class MetaController { public async updatePropertyInFile(property: Partial, newValue: string, file: TFile): Promise { // I'm aware this is hacky. Didn't want to spend a bunch of time rewriting old logic. // This uses the new frontmatter API to update the frontmatter. Later TODO: rewrite old logic to just do this & clean. - if (property.type === MetaType.YAML) { + //@ts-ignore + const frontmatterPosition = this.app.metadataCache.getFileCache(file).frontmatterPosition; + + if (property.type === MetaType.YAML && frontmatterPosition) { const updatedMetaData = `---\n${this.updateYamlProperty(property, newValue, file)}\n---`; - //@ts-ignore - const frontmatterPosition = this.app.metadataCache.getFileCache(file).frontmatterPosition; const fileContents = await this.app.vault.read(file); const deleteFrom = frontmatterPosition.start.offset; diff --git a/src/parser.ts b/src/parser.ts index 2403f14..a165b14 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -28,7 +28,7 @@ export default class MetaEditParser { if (!frontmatter) return []; //@ts-ignore - this is part of the new Obsidian API as of v1.4.1 - const {start, end} = fileCache?.frontmatterPosition; + const {start, end} = fileCache?.frontmatterPosition ?? fileCache?.frontmatter?.position; const filecontent = await this.app.vault.cachedRead(file); const yamlContent: string = filecontent.split("\n").slice(start.line, end.line).join("\n");