feat: allow siyuan-note export path to use Sprig template expressions (#8356)

* feat: allow siyuan-note export path to use Sprig template expressions

* Update export.ts

* feat: allow siyuan-note export path to use Sprig template expressions #8356

* feat: allow siyuan-note export path to use Sprig template expressions #8356

* Update export.ts

* feat: allow siyuan-note export path to use Sprig template expressions #8356

delete empty line
This commit is contained in:
Tron 2025-07-23 17:25:20 +08:00 committed by GitHub
parent 08d6dac4e4
commit 82bdbaa0f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -686,10 +686,10 @@ export const exportMarkdownToSiyuan = async (title: string, content: string) =>
// 确保根路径以/开头
const rootPath = siyuanRootPath?.startsWith('/') ? siyuanRootPath : `/${siyuanRootPath || 'CherryStudio'}`
const renderedRootPath = await renderSprigTemplate(siyuanApiUrl, siyuanToken, rootPath)
// 创建文档
const docTitle = `${title.replace(/[#|\\^\\[\]]/g, '')}`
const docPath = `${rootPath}/${docTitle}`
const docPath = `${renderedRootPath}/${docTitle}`
// 创建文档
await createSiyuanDoc(siyuanApiUrl, siyuanToken, siyuanBoxId, docPath, content)
@ -708,6 +708,30 @@ export const exportMarkdownToSiyuan = async (title: string, content: string) =>
setExportState({ isExporting: false })
}
}
/**
* Sprig
* @param apiUrl API
* @param token API Token
* @param template Sprig
* @returns
*/
async function renderSprigTemplate(apiUrl: string, token: string, template: string): Promise<string> {
const response = await fetch(`${apiUrl}/api/template/renderSprig`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Token ${token}`
},
body: JSON.stringify({ template })
})
const data = await response.json()
if (data.code !== 0) {
throw new Error(`${data.msg || i18n.t('message.error.unknown')}`)
}
return data.data
}
/**
*