From 682755a66f46ac3b130816f5e638d0a5e3255167 Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Thu, 24 Jun 2021 12:50:09 +0200 Subject: [PATCH] Prepare API improvements --- manifest.json | 2 +- package.json | 2 +- src/IMetaEditApi.ts | 2 ++ src/MetaEditApi.ts | 20 +++++++++++++++++++- src/parser.ts | 4 ++-- versions.json | 2 +- 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/manifest.json b/manifest.json index c8770d2..60288fb 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "metaedit", "name": "MetaEdit", - "version": "1.6.13", + "version": "1.6.14", "minAppVersion": "0.12.0", "description": "MetaEdit helps you manage your metadata.", "author": "Christian B. B. Houmann", diff --git a/package.json b/package.json index 75b19e4..4d33451 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "metaedit", - "version": "1.6.13", + "version": "1.6.14", "description": "MetaEdit helps you manage your metadata.", "main": "main.js", "scripts": { diff --git a/src/IMetaEditApi.ts b/src/IMetaEditApi.ts index d437bf8..e7c3c07 100644 --- a/src/IMetaEditApi.ts +++ b/src/IMetaEditApi.ts @@ -4,5 +4,7 @@ export interface IMetaEditApi { autoprop: (propertyName: string) => void; update: (propertyName: string, propertyValue: string, file: TFile | string) => Promise; getPropertyValue: (propertyName: string, file: (TFile | string)) => Promise; + getFilesWithProperty: (propertyName: string) => TFile[]; + createYamlProperty: (propertyName: string, propertyValue: string, file: TFile | string) => Promise; } diff --git a/src/MetaEditApi.ts b/src/MetaEditApi.ts index 1107c07..2035ae3 100644 --- a/src/MetaEditApi.ts +++ b/src/MetaEditApi.ts @@ -13,12 +13,14 @@ export class MetaEditApi { autoprop: this.getAutopropFunction(), update: this.getUpdateFunction(), getPropertyValue: this.getGetPropertyValueFunction(), + getFilesWithProperty: this.getGetFilesWithPropertyFunction(), + createYamlProperty: this.getCreateYamlPropertyFunction() }; } private getAutopropFunction() { return (propertyName: string) => new MetaController(this.plugin.app, this.plugin).handleAutoProperties(propertyName); - } + } private getUpdateFunction(): (propertyName: string, propertyValue: string, file: (TFile | string)) => Promise { return async (propertyName: string, propertyValue: string, file: TFile | string) => { @@ -65,4 +67,20 @@ export class MetaEditApi { return targetProperty.content; } } + + private getGetFilesWithPropertyFunction() { + return (propertyName: string): TFile[] => { + return this.plugin.getFilesWithProperty(propertyName); + } + } + + private getCreateYamlPropertyFunction() { + return async (propertyName: string, propertyValue: string, file: TFile | string) => { + const targetFile = this.getFileFromTFileOrPath(file); + if (!targetFile) return; + + const controller: MetaController = new MetaController(this.plugin.app, this.plugin); + await controller.addYamlProp(propertyName, propertyValue, targetFile); + } + } } \ No newline at end of file diff --git a/src/parser.ts b/src/parser.ts index aca0807..75de3c0 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -2,7 +2,7 @@ import type {App, TFile} from "obsidian"; import {parseYaml} from "obsidian"; import {MetaType} from "./Types/metaType"; -export type Property = {key: string, content: string, type: MetaType}; +export type Property = {key: string, content: any, type: MetaType}; export default class MetaEditParser { private app: App; @@ -34,7 +34,7 @@ export default class MetaEditParser { let metaYaml: Property[] = []; for (const key in parsedYaml) { - metaYaml.push({key, content: parsedYaml[key]?.toString(), type: MetaType.YAML}); + metaYaml.push({key, content: parsedYaml[key], type: MetaType.YAML}); } return metaYaml; diff --git a/versions.json b/versions.json index b103c45..418249f 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "1.6.13": "0.12.0" + "1.6.14": "0.12.0" }