create-new-note-from-template
<%* /* ========= PRECOMPUTE EVERYTHING ========= */
// ---------- TITLE INPUT ---------- let rawTitle = await tp.system.prompt("Enter Note Title");
if (!rawTitle) { rawTitle = "Note " + tp.date.now("YYYY-MM-DD HH:mm"); }
// ---------- SLUG (filename) ---------- let slug = rawTitle .toLowerCase() .trim() .replace(/['’]/g, ”) // clean apostrophes .replace(/[^a-z0-9\s-]/g, ”) // remove punctuation .replace(/\s+/g, '-') // spaces → dashes .replace(/-+/g, '-'); // collapse dashes
await tp.file.rename(slug);
// ---------- HUMAN TITLE ---------- let smallWords = ["and", "or", "the", "a", "an", "of", "in", "on", "to", "for"]; let acronyms = ["ai", "llm", "api"]; // customize as desired
let title = rawTitle .toLowerCase() .split(/\s+/) .map((word, i) ≥ { if (acronyms.includes(word)) { return word.toUpperCase(); } if (i !== 0 && smallWords.includes(word)) { return word; } return word.charAt(0).toUpperCase() + word.slice(1); }) .join(' ');
// ---------- DATES ---------- let today = tp.date.now("YYYY-MM-DD");
// ---------- PATHS ---------- let folderPath = tp.file.folder(true); let fullPath = tp.file.path(false); let relPath = tp.file.path(true); let dirname = app.vault.adapter.getFullPath(folderPath);
// ---------- TAG GENERATION ---------- let segments = folderPath .replace(/.com/g, ”) .toLowerCase() .split('/') .filter(s ≥ s.trim() !== ”);
let uniqueSegments = […new Set(segments)];
let tagLines = [" - obsidian", …uniqueSegments.map(t ≥ - ${t})].join('\n');
/* ========= END PRECOMPUTE ========= */ -%>
title: <% title %> subtitle: <% today %> – SUBTITLE_NEEDED publish: false tags: <% tagLines %> aliases:
- <% title %> template: "z/tmpltr/create-new-note-from-template" filename: <% slug %>.md extension: "md" base: <% slug %> parent: <% tp.file.folder() %> dir: <% folderPath %> dirname: <% dirname %> path: <% relPath %> fullpath: <% fullPath %>