fix: pass actual file creation date to frontmatter generation

Previously used current date instead of file.stat.ctime for the created
field, causing incorrect timestamps in generated frontmatter. Also add
file metadata (created, modified, size) to template application context.
This commit is contained in:
Andrew Beal 2026-05-30 16:03:46 +01:00
parent 1a0c1ccb89
commit 713d82d5bf
3 changed files with 32 additions and 5 deletions

View file

@ -11,4 +11,12 @@ Rewrite the content so it fits the template's structure and headings. Preserve a
If the template section does not resemble a document template (e.g. it is a journal entry, a regular note, or otherwise makes no sense as a template), do not apply it. Instead return exactly the following with no other text:
${Copy.ApplyTemplateCancelled}
Return only the reformatted note with no explanation, preamble, or commentary.`;
Return only the reformatted note with no explanation, preamble, or commentary.
File stats:
Created - {created}
Modified - {modified}
Size - {size}
Current date:
{date}`;

View file

@ -5,7 +5,7 @@ Infer reasonable values for the following fields where the content supports them
- tags: a small set of specific, reusable tags. Use lowercase with no spaces and no # prefix. Prefer hierarchical tags using forward-slash notation (e.g. "type/person", "projects/active") over flat generic tags. Reuse the vault's existing tags (listed below) whenever one genuinely fits the note — this keeps the vault's tagging consistent. Only coin a new tag when none of the existing tags describes an important topic of the note.
- title: a concise title for the note. Wrap in quotes if it contains colons, commas, or other punctuation.
- summary: a single-sentence description of the note
- created: today's date in YYYY-MM-DD format
- created: the note's creation date in YYYY-MM-DD format. Use the "Created" value from the File stats section below — do NOT use today's date.
CRITICAL tags and aliases MUST always be emitted as YAML block-style lists, even when there is only a single value. A scalar string value for these fields is invalid in Obsidian 1.4+ and completely ignored in Obsidian 1.9+.
@ -24,4 +24,10 @@ Only include fields you can fill in confidently from the content — do not inve
Output ONLY the YAML frontmatter fields. Do NOT include the surrounding --- fences, do not repeat the note body, and do not add any explanation, preamble, or commentary. Existing frontmatter on the note will be merged automatically, so return only the fields you are suggesting.
Existing vault tags (prefer reusing these):
{tags}`;
{tags}
File stats:
Created - {created}
Current date:
{date}`;

View file

@ -133,10 +133,18 @@ export class QuickActionsDefinitionsService {
return; // Either an excluded file or the template is empty
}
const prompt = replaceCopy(ApplyTemplatePrompt,
[
new Date(file.stat.ctime).toString(),
new Date(file.stat.mtime).toString(),
file.stat.size.toString(),
new Date().toString()
]);
const notice = this.showNotice("Applying template...");
try {
const context = `${Copy.ApplyTemplateTemplateSeparator}\n${templateContent}\n${Copy.ApplyTemplateContentSeparator}\n${content}`;
const result = await this.performAction(ApplyTemplatePrompt, context);
const result = await this.performAction(prompt, context);
if (result && result.trim() !== Copy.ApplyTemplateCancelled.toString()) {
await this.fileSystemService.writeToFile(file, result, false, false);
}
@ -302,7 +310,12 @@ export class QuickActionsDefinitionsService {
}
const availableTags = this.vaultcacheService.tags;
const prompt = replaceCopy(GenerateFrontmatterPrompt, [Array.from(availableTags).join("\n")]);
const prompt = replaceCopy(GenerateFrontmatterPrompt,
[
Array.from(availableTags).join("\n"),
new Date(file.stat.ctime).toString(),
new Date().toString()
]);
const notice = this.showNotice("Generating frontmatter...");
try {