Skip to content

<%* const rawTitle = await tp.system.prompt('文章标题') if (!rawTitle) { new Notice('已取消创建文章') return }

const title = rawTitle.trim().replace(/[\/😗?"<>|]/g, '-').replace(/\s+/g, ' ') if (!title) { new Notice('文章标题不能为空') return }

const folderPath = title const indexPath = ${folderPath}/index.md if (app.vault.getAbstractFileByPath(indexPath)) { new Notice(文章已存在:${title}) return }

await app.vault.createFolder(folderPath) await app.vault.createFolder(${folderPath}/assets)

const created = tp.date.now('YYYY-MM-DD HH:mm:ss') const content = [ '---', title: ${JSON.stringify(title)}, created: '${created}', 'Tags: ""', 'Publish: false', '---', # ${title}, '', '' ].join('\n') const article = await app.vault.create(indexPath, content) await app.workspace.getLeaf(true).openFile(article) await tp.file.delete() %>