touchdesigner-mcp-server
Version:
MCP server for TouchDesigner
26 lines (25 loc) • 928 B
JavaScript
import { readFileSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import Mustache from "mustache";
const templatesDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "./templates/markdown");
const templateCache = new Map();
export function renderMarkdownTemplate(templateName, context = {}) {
const template = loadTemplate(templateName);
return Mustache.render(template, context).trim();
}
function loadTemplate(name) {
const fileName = `${name}.md`;
const fullPath = path.join(templatesDir, fileName);
if (!templateCache.has(fileName)) {
let content;
try {
content = readFileSync(fullPath, "utf-8");
}
catch {
content = readFileSync(path.join(templatesDir, "default.md"), "utf-8");
}
templateCache.set(fileName, content);
}
return templateCache.get(fileName) ?? "";
}