<%* // 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); } %>