FileManager โ€บ processFrontMatter

FileManager.processFrontMatter() method

Atomically read, modify, and save the frontmatter of a note. The frontmatter is passed in as a JS object, and should be mutated directly to achieve the desired result.

Remember to handle errors thrown by this method.

Signature:

processFrontMatter(file: TFile, fn: (frontmatter: any) => void, options?: DataWriteOptions): Promise<void>;

Parameters

ParameterTypeDescription
fileTFilethe file to be modified. Must be a Markdown file.
fn(frontmatter: any) โ‡’ voida callback function which mutates the frontmatter object synchronously.
optionsDataWriteOptions(Optional) write options.

Returns:

Promise<void>

Exceptions

YAMLParseError if the YAML parsing fails

any errors that your callback function throws

Example

app.fileManager.processFrontMatter(file, (frontmatter) => {
    frontmatter['key1'] = value;
    delete frontmatter['key2'];
});