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
Parameter | Type | Description |
---|---|---|
file | TFile | the file to be modified. Must be a Markdown file. |
fn | (frontmatter: any) โ void | a callback function which mutates the frontmatter object synchronously. |
options | DataWriteOptions | (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'];
});