QoL - AddNoteFromMetadataModal now fetch Yaml metadata at onOpen() start

This commit is contained in:
Noah Boos 2025-04-18 15:31:43 +02:00
parent cce32cfdbe
commit 00ced430b3

View file

@ -1,5 +1,5 @@
import {
App,
App, FrontMatterCache,
getFrontMatterInfo,
Modal,
Notice,
@ -62,6 +62,15 @@ export class AddNoteFromMetadataModal extends Modal {
*/
const { contentEl } = this;
/**
* @type {TFile} activeFileData
* The file defined as active in the Obsidian instance.
* @type {FrontMatterCache} yaml
* The YAML metadata stored in object under the key: "value" format.
*/
const activeFileData: TFile = this.app.workspace.getActiveFile();
const yaml: FrontMatterCache = this.app.metadataCache.getFileCache(activeFileData).frontmatter;
// Add the title and subtitle to the modal.
AddTitle(contentEl, "Add a new note using metadata");
AddSubtitle(contentEl, "Deck & Model");
@ -120,18 +129,6 @@ export class AddNoteFromMetadataModal extends Modal {
*/
const selectedModel: Object = FetchModelByName(this.plugin, value);
/**
* @type {TFile} activeFileData
* The file defined as active in the Obsidian instance.
* @type {string} fileContent
* The raw content of the file, including frontmatter and regular text.
* @type {Object} yaml
* The YAML metadata stored in object under the key: "value" format.
*/
const activeFileData: TFile = this.app.workspace.getActiveFile();
const fileContent: string = await this.app.vault.cachedRead(activeFileData);
const yaml: Object = parseYaml(getFrontMatterInfo(fileContent).frontmatter);
/**
* @type {Array} fieldsGroupData
* An array of input data storing as separate object (1 objet = 1 input) the keys used to create each label-input pair and the values of each input.