You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the view can become quite time-consuming when you have to manage several export commands depending on the type of page.
It would be amazing if we could list the export commands to be executed in the frontmatter, with their arguments, and then call them with a single command Execute all commands on page.
The good news is that the Obsidian API can already handle frontmatter inner properties. Here is an example of code in JS to parse export and get its values:
/** * Get inside the frontmatter the value of the property `propertyName`. * @param {App} app A reference to the Obsidian `app`. * @param {Obsidian} obsidian A reference to the Obsidian API. * @param {TFile} file Vault file to parse. * @param {string} propertyName Property name of the value to get. * @returns {any|null} Value inside the frontmatter of `file`. * @throws {Error} If the property doesn't exists. */staticgetFrontMatterEntry(app,obsidian,file,propertyName){constfileFrontMatter=app.metadataCache.getFileCache(file)?.frontmatter;if(!fileFrontMatter||!Object.keys(fileFrontMatter).includes(propertyName))thrownewError(`The property '${propertyName}' doesn't exists in the file '${file.path}'.`);constpropertyValue=obsidian.parseFrontMatterEntry(fileFrontMatter,propertyName);returnpropertyValue;}/** * Check if the frontmatter has a the property `propertyName` * @alias UtilityObsidian:getFrontMatterAliases * @param {App} app A reference to the Obsidian `app`. * @param {TFile} file Vault file to parse. * @param {string} propertyName Property name to check. * @returns {boolean} `true` if frontmatter has the property; otherwise `false`. */statichasFrontMatterEntry(app,file,propertyName){constfileFrontMatter=app.metadataCache.getFileCache(file)?.frontmatter;if(!fileFrontMatter||!Object.keys(fileFrontMatter).includes(propertyName))returnfalse;returntrue;}/** * Extract the command arguments defined in the frontmatter property 'export' of the invoker page `invokerPage`. * @param {TFile} invokerPage Page that call the script. * @returns {Map<string,object>} Args of each command defined in the page. Map is in the form `{ key: <command-name>, value: <command-args-object> }`. * @throws {Error} If `invokerPage` has not property 'script' in its frontmatter, or if a script declaration is malformed. */functionextractAllCommandArgs(invokerPage){if(!MyClass.hasFrontMatterEntry(Context.app,invokerPage,"export")){thrownewError(`The frontmatter property 'export' is missing in '${invokerPage.basename}'!`);}/** @type {object} */constallScripts=MyClass.getFrontMatterEntry(Context.app,Context.obsidian,invokerPage,"export");if(allScripts==null)thrownewError(`The frontmatter property 'export' is not defined in '${invokerPage.basename}'!`);/** @type {Map<string,Object|null>} */constscriptMap=newMap(Object.entries(allScripts));if(Array.from(scriptMap.values()).includes(null))thrownewError(`The frontmatter property 'export' is malformed! An argument list cannot be null, use '{}'.`);returnscriptMap;}
ps: Thank you very much for this very useful plugin.
The text was updated successfully, but these errors were encountered:
Hello dear dev!
Using the view can become quite time-consuming when you have to manage several export commands depending on the type of page.
It would be amazing if we could list the export commands to be executed in the frontmatter, with their arguments, and then call them with a single command
Execute all commands on page
.A such page frontmatter declaration could be:
The good news is that the Obsidian API can already handle frontmatter inner properties. Here is an example of code in JS to parse
export
and get its values:ps: Thank you very much for this very useful plugin.
The text was updated successfully, but these errors were encountered: