<%* // Devices Template - Dynamically reads from fileClass schema // Single source of truth: Templates/fileClasses/devices.md

// Helper: parse Select options for a given field from the fileClass YAML function getSelectOptions(yaml, fieldName) { const chunks = yaml.split(/(?=\n - name:)/); const fieldChunk = chunks.find(c c.includes(- name: ${fieldName})); if (!fieldChunk) return []; const optionMatches = […fieldChunk.matchAll(/- option: (\S+)/g)]; return optionMatches.map(m m[1]); }

// Read fileClass schema const fileClassPath = “Templates/fileClasses/devices.md”; const fileClassContent = await app.vault.adapter.read(fileClassPath); const yamlMatch = fileClassContent.match(/^---\n([\s\S]*?)\n---/); if (!yamlMatch) { new Notice(“Error: Could not parse fileClass schema”); return; } const yamlBody = yamlMatch[1];

// Prompts const manufacturer = await tp.system.prompt(“Manufacturer (e.g., Plugable, Apple, Sony):”); if (!manufacturer) return;

const model = await tp.system.prompt(“Model (e.g., UD-ULTC4K, MacBook Pro M4 Max):”); if (!model) return;

// Rename file to “Manufacturer Model” const filename = ${manufacturer} ${model}; await tp.file.rename(filename);

// Get category from fileClass options const categories = getSelectOptions(yamlBody, “category”); const selectedCategory = await tp.system.suggester( categories, categories, false, “Category:” );

// Get status from fileClass options, default to “active” const statuses = getSelectOptions(yamlBody, “status”); const selectedStatus = await tp.system.suggester( statuses, statuses, false, “Status (default: active):” ) || “active”;

// Extract field names from fileClass schema const fieldMatches = […yamlBody.matchAll(/- name: ([a-z_]+)/g)]; const fields = fieldMatches.map(match match[1]);

// Start frontmatter tR += ”---\n”; tR += “model: ” + JSON.stringify(model) + “\n”; tR += “manufacturer: ” + JSON.stringify(manufacturer) + “\n”; tR += “created: ” + tp.date.now(“YYYY-MM-DD”) + “\n”; tR += “tags:\n”; tR += ” - devices\n”;

// Generate remaining fields from schema for (const fieldName of fields) { // Skip fields we already added if ([“model”, “manufacturer”, “created”, “tags”].includes(fieldName)) continue;

if (fieldName === "category" && selectedCategory) {
    tR += "category: " + selectedCategory + "\n";
} else if (fieldName === "category" && !selectedCategory) {
    tR += "category: \n";
} else if (fieldName === "status") {
    tR += "status: " + selectedStatus + "\n";
} else if (fieldName === "manuals") {
    tR += "manuals: []\n";
} else {
    tR += fieldName + ": \n";
}

}

tR += ”---\n”; -%>

Specs

Notes