mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 06:49:02 +08:00
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:
parent
08d6dac4e4
commit
82bdbaa0f4
@ -686,10 +686,10 @@ export const exportMarkdownToSiyuan = async (title: string, content: string) =>
|
|||||||
|
|
||||||
// 确保根路径以/开头
|
// 确保根路径以/开头
|
||||||
const rootPath = siyuanRootPath?.startsWith('/') ? siyuanRootPath : `/${siyuanRootPath || 'CherryStudio'}`
|
const rootPath = siyuanRootPath?.startsWith('/') ? siyuanRootPath : `/${siyuanRootPath || 'CherryStudio'}`
|
||||||
|
const renderedRootPath = await renderSprigTemplate(siyuanApiUrl, siyuanToken, rootPath)
|
||||||
// 创建文档
|
// 创建文档
|
||||||
const docTitle = `${title.replace(/[#|\\^\\[\]]/g, '')}`
|
const docTitle = `${title.replace(/[#|\\^\\[\]]/g, '')}`
|
||||||
const docPath = `${rootPath}/${docTitle}`
|
const docPath = `${renderedRootPath}/${docTitle}`
|
||||||
|
|
||||||
// 创建文档
|
// 创建文档
|
||||||
await createSiyuanDoc(siyuanApiUrl, siyuanToken, siyuanBoxId, docPath, content)
|
await createSiyuanDoc(siyuanApiUrl, siyuanToken, siyuanBoxId, docPath, content)
|
||||||
@ -708,6 +708,30 @@ export const exportMarkdownToSiyuan = async (title: string, content: string) =>
|
|||||||
setExportState({ isExporting: false })
|
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
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建思源笔记文档
|
* 创建思源笔记文档
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user