diff --git a/src/renderer/src/utils/export.ts b/src/renderer/src/utils/export.ts index d498e86de6..ee67b989aa 100644 --- a/src/renderer/src/utils/export.ts +++ b/src/renderer/src/utils/export.ts @@ -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 { + 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 +} /** * 创建思源笔记文档