From 713d82d5bf234cc87f9f0407b5ee86d13e7a3580 Mon Sep 17 00:00:00 2001 From: Andrew Beal Date: Sat, 30 May 2026 16:03:46 +0100 Subject: [PATCH] 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. --- .../QuickActionPrompts/ApplyTemplatePrompt.ts | 10 +++++++++- .../GenerateFrontmatterPrompt.ts | 10 ++++++++-- .../QuickActionsDefinitionsService.ts | 17 +++++++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/AIPrompts/QuickActionPrompts/ApplyTemplatePrompt.ts b/AIPrompts/QuickActionPrompts/ApplyTemplatePrompt.ts index 61c96b2..9a3fe1c 100644 --- a/AIPrompts/QuickActionPrompts/ApplyTemplatePrompt.ts +++ b/AIPrompts/QuickActionPrompts/ApplyTemplatePrompt.ts @@ -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.`; \ No newline at end of file +Return only the reformatted note with no explanation, preamble, or commentary. + +File stats: +Created - {created} +Modified - {modified} +Size - {size} + +Current date: +{date}`; \ No newline at end of file diff --git a/AIPrompts/QuickActionPrompts/GenerateFrontmatterPrompt.ts b/AIPrompts/QuickActionPrompts/GenerateFrontmatterPrompt.ts index adc1a57..d2b8ef3 100644 --- a/AIPrompts/QuickActionPrompts/GenerateFrontmatterPrompt.ts +++ b/AIPrompts/QuickActionPrompts/GenerateFrontmatterPrompt.ts @@ -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}`; diff --git a/Services/QuickActions/QuickActionsDefinitionsService.ts b/Services/QuickActions/QuickActionsDefinitionsService.ts index bfd1f25..b9c32cc 100644 --- a/Services/QuickActions/QuickActionsDefinitionsService.ts +++ b/Services/QuickActions/QuickActionsDefinitionsService.ts @@ -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 {