MCPcopy
hub / github.com/callumalpass/tasknotes / processTemplateFrontmatter

Function processTemplateFrontmatter

src/utils/templateProcessor.ts:109–140  ·  view source on GitHub ↗

* Process template variables in frontmatter

(
	frontmatterContent: string,
	taskData: TemplateData | ICSTemplateData
)

Source from the content-addressed store, hash-verified

107 * Process template variables in frontmatter
108 */
109function 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

Callers 1

processTemplateFunction · 0.85

Calls 5

parseMethod · 0.80
warnMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected