<%* // 1. μ¬μ©μλ‘λΆν° μ λͺ© μ λ ₯ λ°κΈ° (λΉ κ°μΌλ‘ μμ) const titleInput = await tp.system.prompt(“ν¬μ€νΈ μ λͺ©μ μ λ ₯νμΈμ (ESC: μ·¨μ)”);
// 2. μ λͺ© μ λ ₯ κ²μ¦ (μ·¨μνκ±°λ 곡백μ΄λ©΄ μ€λ¨) if (titleInput === null || titleInput.trim() === “”) { new Notice("β μ λͺ©μ΄ μ λ ₯λμ§ μμ μμ±μ μ·¨μν©λλ€."); return; }
const title = titleInput.trim(); const baseSection = “posts”; const today = tp.date.now(“YYMMDD”);
// 3. μ¦λΆ λ²νΈ κ³μ° (ν΄λλͺ
μ μ€μ§ YYMMDD_XXX νμ)
let index = 1;
let targetFolderPath = “”;
while (index <= 999) {
const padIndex = String(index).padStart(3, ‘0’);
const folderName = ${today}_${padIndex}; // μ λͺ© μ μΈ, λ μ§μ λ²νΈλ§ μ¬μ©
targetFolderPath = ${baseSection}/${folderName};
if (!app.vault.getAbstractFileByPath(targetFolderPath)) break;
index++;
}
// 4. ν΄λ μμ± λ° λ΄μ© κ΅¬μ± try { await app.vault.createFolder(targetFolderPath); const nowTime = tp.date.now(“YYYY-MM-DDTHH:mm:ss”);
// Frontmatterμ λ³Έλ¬Έμ μ
λ ₯λ°μ μ λͺ© λ°μ
const content = `---
title: “${title}” categories:
- UNKNOWN tags:
- default date: ${nowTime} draft: false
${title}
`;
// 5. index.md νμΌ μμ±
const filePath = `${targetFolderPath}/index.md`;
const newFile = await app.vault.create(filePath, content);
// 6. μ€ν μ€μΈ νμ¬ νμΌ μ 보 μ μ₯ (μ 리μ©)
const currentFile = tp.config.target_file;
// 7. ν¬μ»€μ€ μ ν λ° Untitled νμΌ μμ
setTimeout(async () => {
const activeLeaf = app.workspace.getMostRecentLeaf();
if (activeLeaf) {
await activeLeaf.openFile(newFile, { active: true });
// μ€νμ μ¬μ©λ λΉ νμΌ μμ
if (currentFile && currentFile.name.includes("Untitled")) {
await app.vault.trash(currentFile, true);
}
}
// μλν°μ 컀μ ν¬μ»€μ€
app.workspace.activeLeaf.view.editor?.focus();
new Notice(`β
'${title}' ν¬μ€νΈκ° ${targetFolderPath}μ μμ±λμμ΅λλ€.`);
}, 300);
} catch (err) { console.error(err); new Notice("β οΈ μ€λ₯ λ°μ: " + err.message); } %>