mirror of
https://github.com/devonthesofa/obsidian-note-status.git
synced 2026-07-22 05:45:04 +00:00
chore: use the MedataCache to read frontmatter without async response
This commit is contained in:
parent
636976d57e
commit
ae6088fc25
1 changed files with 10 additions and 10 deletions
|
|
@ -73,22 +73,22 @@ export function updateFrontmatterProperty(
|
|||
* Reads frontmatter property from file
|
||||
* Always returns an array (even if the property is stored as a string)
|
||||
*/
|
||||
export async function getFrontmatterProperty(
|
||||
export function getFrontmatterProperty(
|
||||
app: App,
|
||||
file: TFile,
|
||||
property: string
|
||||
): Promise<string[] | null> {
|
||||
): string[] | null {
|
||||
const cache = app.metadataCache.getFileCache(file);
|
||||
|
||||
if (cache?.frontmatter && property in cache.frontmatter) {
|
||||
const value = cache.frontmatter[property];
|
||||
|
||||
// Always return as array
|
||||
if (Array.isArray(value)) {
|
||||
return value;
|
||||
} else if (value !== null && value !== undefined) {
|
||||
return [value.toString()];
|
||||
}
|
||||
const value = cache.frontmatter[property];
|
||||
|
||||
// Always return as array
|
||||
if (Array.isArray(value)) {
|
||||
return value;
|
||||
} else if (value !== null && value !== undefined) {
|
||||
return [value.toString()];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Reference in a new issue