mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 02:52:47 +08:00
🎨 提供 Sprig 模板渲染 API Fix https://github.com/siyuan-note/siyuan/issues/7767
This commit is contained in:
parent
986166ff8b
commit
13d88644a8
22
API.md
22
API.md
@ -35,6 +35,7 @@
|
|||||||
* [Execute SQL query](#Execute-SQL-query)
|
* [Execute SQL query](#Execute-SQL-query)
|
||||||
* [Templates](#Templates)
|
* [Templates](#Templates)
|
||||||
* [Render a template](#Render-a-template)
|
* [Render a template](#Render-a-template)
|
||||||
|
* [Render Sprig](#Render-Sprig)
|
||||||
* [File](#File)
|
* [File](#File)
|
||||||
* [Get file](#Get-file)
|
* [Get file](#Get-file)
|
||||||
* [Put file](#Put-file)
|
* [Put file](#Put-file)
|
||||||
@ -831,6 +832,27 @@ View API token in <kbd>Settings - About</kbd>, request header: `Authorization: T
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 渲染 Sprig
|
||||||
|
|
||||||
|
* `/api/template/renderSprig`
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"template": "/daily note/{{now | date \"2006/01\"}}/{{now | date \"2006-01-02\"}}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* `template`: template content
|
||||||
|
* Return value
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": "/daily note/2023/03/2023-03-24"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## File
|
## File
|
||||||
|
|
||||||
### Get file
|
### Get file
|
||||||
|
22
API_zh_CN.md
22
API_zh_CN.md
@ -35,6 +35,7 @@
|
|||||||
* [执行 SQL 查询](#执行-SQL-查询)
|
* [执行 SQL 查询](#执行-SQL-查询)
|
||||||
* [模板](#模板)
|
* [模板](#模板)
|
||||||
* [渲染模板](#渲染模板)
|
* [渲染模板](#渲染模板)
|
||||||
|
* [渲染 Sprig](#渲染-Sprig)
|
||||||
* [文件](#文件)
|
* [文件](#文件)
|
||||||
* [获取文件](#获取文件)
|
* [获取文件](#获取文件)
|
||||||
* [写入文件](#写入文件)
|
* [写入文件](#写入文件)
|
||||||
@ -824,6 +825,27 @@
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 渲染 Sprig
|
||||||
|
|
||||||
|
* `/api/template/renderSprig`
|
||||||
|
* 参数
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"template": "/daily note/{{now | date \"2006/01\"}}/{{now | date \"2006-01-02\"}}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* `template`:模板内容
|
||||||
|
* 返回值
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": "/daily note/2023/03/2023-03-24"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 文件
|
## 文件
|
||||||
|
|
||||||
### 获取文件
|
### 获取文件
|
||||||
|
@ -248,6 +248,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||||||
|
|
||||||
ginServer.Handle("POST", "/api/template/render", model.CheckAuth, renderTemplate)
|
ginServer.Handle("POST", "/api/template/render", model.CheckAuth, renderTemplate)
|
||||||
ginServer.Handle("POST", "/api/template/docSaveAsTemplate", model.CheckAuth, model.CheckReadonly, docSaveAsTemplate)
|
ginServer.Handle("POST", "/api/template/docSaveAsTemplate", model.CheckAuth, model.CheckReadonly, docSaveAsTemplate)
|
||||||
|
ginServer.Handle("POST", "/api/template/renderSprig", model.CheckAuth, model.CheckReadonly, renderSprig)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/transactions", model.CheckAuth, model.CheckReadonly, performTransactions)
|
ginServer.Handle("POST", "/api/transactions", model.CheckAuth, model.CheckReadonly, performTransactions)
|
||||||
|
|
||||||
|
@ -25,6 +25,25 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func renderSprig(c *gin.Context) {
|
||||||
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
|
arg, ok := util.JsonArg(c, ret)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
template := arg["template"].(string)
|
||||||
|
content, err := model.RenderGoTemplate(template)
|
||||||
|
if nil != err {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = util.EscapeHTML(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ret.Data = content
|
||||||
|
}
|
||||||
|
|
||||||
func docSaveAsTemplate(c *gin.Context) {
|
func docSaveAsTemplate(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
Loading…
Reference in New Issue
Block a user