* Process template variables in frontmatter
( frontmatterContent: string, taskData: TemplateData | ICSTemplateData )
| 107 | * Process template variables in frontmatter |
| 108 | */ |
| 109 | function processTemplateFrontmatter( |
| 110 | frontmatterContent: string, |
| 111 | taskData: TemplateData | ICSTemplateData |
| 112 | ): Record<string, unknown> { |
| 113 | try { |
| 114 | // First, process template variables in the raw YAML text with YAML-safe replacements |
| 115 | const processedYamlText = quoteTemplaterYamlScalars( |
| 116 | processTemplateVariablesForYaml(frontmatterContent, taskData) |
| 117 | ); |
| 118 | |
| 119 | // Then parse the processed YAML |
| 120 | const parsedFrontmatter = YAML.parse(processedYamlText); |
| 121 | |
| 122 | // Return empty object if parsing failed or result is not an object |
| 123 | if (typeof parsedFrontmatter !== "object" || parsedFrontmatter === null) { |
| 124 | tasknotesLogger.warn("Template frontmatter did not parse to a valid object", { |
| 125 | category: "validation", |
| 126 | operation: "template-frontmatter-did-not-parse-valid-object", |
| 127 | }); |
| 128 | return {}; |
| 129 | } |
| 130 | |
| 131 | return parsedFrontmatter; |
| 132 | } catch (error) { |
| 133 | tasknotesLogger.error("Error processing template frontmatter:", { |
| 134 | category: "validation", |
| 135 | operation: "processing-template-frontmatter", |
| 136 | error: error, |
| 137 | }); |
| 138 | return {}; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Process template variables in body content |
no test coverage detected