Skip to content

Commit

Permalink
API: Add getPropertyValue() function
Browse files Browse the repository at this point in the history
  • Loading branch information
chhoumann committed Jun 14, 2021
1 parent a37b067 commit ee90cf1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "metaedit",
"name": "MetaEdit",
"version": "1.6.12",
"version": "1.6.13",
"minAppVersion": "0.12.0",
"description": "MetaEdit helps you manage your metadata.",
"author": "Christian B. B. Houmann",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metaedit",
"version": "1.6.12",
"version": "1.6.13",
"description": "MetaEdit helps you manage your metadata.",
"main": "main.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/IMetaEditApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import type {TFile} from "obsidian";
export interface IMetaEditApi {
autoprop: (propertyName: string) => void;
update: (propertyName: string, propertyValue: string, file: TFile | string) => Promise<void>;
getPropertyValue: (propertyName: string, file: (TFile | string)) => Promise<any>;
}

16 changes: 16 additions & 0 deletions src/MetaEditApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class MetaEditApi {
return {
autoprop: this.getAutopropFunction(),
update: this.getUpdateFunction(),
getPropertyValue: this.getGetPropertyValueFunction(),
};
}

Expand Down Expand Up @@ -49,4 +50,19 @@ export class MetaEditApi {

return targetFile;
}

private getGetPropertyValueFunction(): (propertyName: string, file: (TFile | string)) => Promise<any> {
return async (propertyName: string, file: TFile | string) => {
const targetFile = this.getFileFromTFileOrPath(file);
if (!targetFile) return;

const controller: MetaController = new MetaController(this.plugin.app, this.plugin);
const propsInFile: Property[] = await controller.getPropertiesInFile(targetFile);

const targetProperty = propsInFile.find(prop => prop.key === propertyName);
if (!targetProperty) return;

return targetProperty.content;
}
}
}
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"1.6.12": "0.12.0"
"1.6.13": "0.12.0"
}

0 comments on commit ee90cf1

Please sign in to comment.