Templater code that appears in the metadata section of the template (e.g., updated: <% tp.file.last_modified_date("YYYY-MM-DD HH:mm:ss") %>) is not evaluated when regenerating metadata
If the template starts with a Templater expression, rather than ---, regeneratedMetadata will never be initialized and all existing metadata will be deleted from the file
Note: I have not explicitly tried this with the plugin; this behavior is deduced from the code flow and testing snippets of the code in a Typescript sandbox
The regenerateAllGameNotesMetadata() function does not invoke Templater like the createNewGameNote() function does
Solution:
I'm not super familiar with Templater, but, if there is an in-memory evaluation function, you could pass your regeneratedContent through that. Otherwise, you might have to write it to a temp file, run useTemplaterPluginInFile() on it, read the contents back into memory, and delete the temp file
Initializing regeneratedMetadata to existingMetadata should fix this issue
If the conditionals are true, regeneratedMetadata should be overwritten with the new content
If they are false, the existing metadata should be maintained
To Reproduce
Create a template file with a Templater expression in one of the properties
Problem
updated: <% tp.file.last_modified_date("YYYY-MM-DD HH:mm:ss") %>
) is not evaluated when regenerating metadata---
,regeneratedMetadata
will never be initialized and all existing metadata will be deleted from the filemain.ts
Obsidian Version: 1.7.4 Obsidian Installer Version: 1.5.3 Game Search Version: 0.2.12
Cause:
The
regenerateAllGameNotesMetadata()
function does not invoke Templater like thecreateNewGameNote()
function doesSolution:
regeneratedContent
through that. Otherwise, you might have to write it to a temp file, runuseTemplaterPluginInFile()
on it, read the contents back into memory, and delete the temp fileregeneratedMetadata
toexistingMetadata
should fix this issueregeneratedMetadata
should be overwritten with the new contentTo Reproduce
---
)Expected behavior