Skip to content

/api/template

render

  • 🔥 渲染模板
  • /api/template/render

请求

ts
/**
 * render template file
 */
export interface IPayload {
    /**
     * document block ID
     */
    readonly id: string;
    /**
     * the absolute path of Kramdown template file
     */
    readonly path: string;
}
json5
/**
 * schemas/kernel/api/template/render/payload.schema.json5
 * 渲染模板文件
 * REF: https://github.com/siyuan-note/siyuan/blob/master/API.md#render-a-template
 * REF: https://github.com/siyuan-note/siyuan/blob/v2.9.3/kernel/api/template.go#L68-L94
 * @pathname: /api/template/render
 * @version: 2.9.3
 */
{
    $schema: 'https://json-schema.org/draft/2020-12/schema',
    $id: 'https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/template/render/payload.schema.json5',
    $comment: 'v2.9.3',
    $ref: '#/$defs/root',
    $defs: {
        root: {
            title: 'payload body',
            description: 'render template file',

            type: 'object',
            additionalProperties: false,
            required: [
                'id',
                'path',
            ],
            properties: {
                id: {
                    /**
                     * 文档块 ID, 用于渲染模板时调用一些文档相关的内置属性与方法
                     * REF: siyuan://blocks/20210104091309-gjkg3u5
                     */
                    type: 'string',
                    description: 'document block ID',
                    pattern: '^\\d{14}-[0-9a-z]{7}$',
                },
                path: {
                    // Kramdown 模板文件(*.md)的绝对路径
                    type: 'string',
                    description: 'the absolute path of Kramdown template file',
                },
            },
        },
    },
}
json
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/template/render/payload.schema.json",
    "$comment": "v2.9.3",
    "$ref": "#/$defs/root",
    "$defs": {
        "root": {
            "title": "payload body",
            "description": "render template file",
            "type": "object",
            "additionalProperties": false,
            "required": [
                "id",
                "path"
            ],
            "properties": {
                "id": {
                    "type": "string",
                    "description": "document block ID",
                    "pattern": "^\\d{14}-[0-9a-z]{7}$"
                },
                "path": {
                    "type": "string",
                    "description": "the absolute path of Kramdown template file"
                }
            }
        }
    }
}

响应

ts
/**
 * render template file
 */
export interface IResponse {
    /**
     * status code
     */
    readonly code: number;
    readonly data: IData;
    /**
     * status message
     */
    readonly msg: string;
}

/**
 * the result of rendering
 */
export interface IData {
    /**
     * the DOM string of template rendering result
     */
    readonly content: string;
    /**
     * the absolute path of Kramdown template file
     */
    readonly path: string;
}
json5
/**
 * schemas/kernel/api/template/render/response.schema.json5
 * 渲染模板文件
 * REF: https://github.com/siyuan-note/siyuan/blob/master/API.md#render-a-template
 * REF: https://github.com/siyuan-note/siyuan/blob/v2.9.3/kernel/api/template.go#L68-L94
 * @pathname: /api/template/render
 * @version: 2.9.3
 */
{
    $schema: 'https://json-schema.org/draft/2020-12/schema',
    $id: 'https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/template/render/response.schema.json5',
    $comment: 'v2.9.3',
    $ref: '#/$defs/root',
    $defs: {
        root: {
            title: 'response body',
            description: 'render template file',

            type: 'object',
            additionalProperties: false,
            required: [
                'code',
                'msg',
                'data',
            ],
            properties: {
                code: {
                    type: 'integer',
                    description: 'status code',
                },
                msg: {
                    type: 'string',
                    description: 'status message',
                },
                data: {
                    $ref: '#/$defs/data',
                },
            },
        },
        data: {
            title: 'IData',
            description: 'the result of rendering',

            type: 'object',
            additionalProperties: false,
            required: [
                'path',
                'content',
            ],
            properties: {
                path: {
                    // 模板文件绝对路径
                    type: 'string',
                    description: 'the absolute path of Kramdown template file',
                },
                content: {
                    // 模板渲染结果的 DOM 字符串
                    type: 'string',
                    description: 'the DOM string of template rendering result',
                },
            },
        },
    },
}
json
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/template/render/response.schema.json",
    "$comment": "v2.9.3",
    "$ref": "#/$defs/root",
    "$defs": {
        "root": {
            "title": "response body",
            "description": "render template file",
            "type": "object",
            "additionalProperties": false,
            "required": [
                "code",
                "msg",
                "data"
            ],
            "properties": {
                "code": {
                    "type": "integer",
                    "description": "status code"
                },
                "msg": {
                    "type": "string",
                    "description": "status message"
                },
                "data": {
                    "$ref": "#/$defs/data"
                }
            }
        },
        "data": {
            "title": "IData",
            "description": "the result of rendering",
            "type": "object",
            "additionalProperties": false,
            "required": [
                "path",
                "content"
            ],
            "properties": {
                "path": {
                    "type": "string",
                    "description": "the absolute path of Kramdown template file"
                },
                "content": {
                    "type": "string",
                    "description": "the DOM string of template rendering result"
                }
            }
        }
    }
}

renderSprig

  • 🔥 渲染 Sprig 模板字符串
  • /api/template/renderSprig

请求

ts
/**
 * render Sprig template
 */
export interface IPayload {
    /**
     * sprig template
     */
    readonly template: string;
}
json5
/**
 * schemas/kernel/api/template/renderSprig/payload.schema.json5
 * 渲染 Sprig 模板
 * REF: https://github.com/siyuan-note/siyuan/blob/master/API.md#render-sprig
 * REF: https://github.com/siyuan-note/siyuan/blob/v2.9.3/kernel/api/template.go#L28-L45
 * @pathname: /api/template/renderSprig
 * @version: 2.9.3
 */
{
    $schema: 'https://json-schema.org/draft/2020-12/schema',
    $id: 'https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/template/renderSprig/payload.schema.json5',
    $comment: 'v2.9.3',
    $ref: '#/$defs/root',
    $defs: {
        root: {
            title: 'payload body',
            description: 'render Sprig template',

            type: 'object',
            additionalProperties: false,
            required: [
                'template',
            ],
            properties: {
                template: {
                    type: 'string',
                    description: 'sprig template',
                },
            },
        },
    },
}
json
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/template/renderSprig/payload.schema.json",
    "$comment": "v2.9.3",
    "$ref": "#/$defs/root",
    "$defs": {
        "root": {
            "title": "payload body",
            "description": "render Sprig template",
            "type": "object",
            "additionalProperties": false,
            "required": [
                "template"
            ],
            "properties": {
                "template": {
                    "type": "string",
                    "description": "sprig template"
                }
            }
        }
    }
}

响应

ts
/**
 * render Sprig template
 */
export interface IResponse {
    /**
     * status code
     */
    readonly code: number;
    /**
     * the result of rendering the Sprig template
     */
    readonly data: string;
    /**
     * status message
     */
    readonly msg: string;
}
json5
/**
 * schemas/kernel/api/template/renderSprig/response.schema.json5
 * 渲染 Sprig 模板
 * REF: https://github.com/siyuan-note/siyuan/blob/master/API.md#render-sprig
 * REF: https://github.com/siyuan-note/siyuan/blob/v2.9.3/kernel/api/template.go#L28-L45
 * @pathname: /api/template/renderSprig
 * @version: 2.9.3
 */
{
    $schema: 'https://json-schema.org/draft/2020-12/schema',
    $id: 'https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/template/renderSprig/response.schema.json5',
    $comment: 'v2.9.3',
    $ref: '#/$defs/root',
    $defs: {
        root: {
            title: 'response body',
            description: 'render Sprig template',

            type: 'object',
            additionalProperties: false,
            required: [
                'code',
                'msg',
                'data',
            ],
            properties: {
                code: {
                    type: 'integer',
                    description: 'status code',
                },
                msg: {
                    type: 'string',
                    description: 'status message',
                },
                data: {
                    type: 'string',
                    description: 'the result of rendering the Sprig template',
                },
            },
        },
    },
}
json
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/template/renderSprig/response.schema.json",
    "$comment": "v2.9.3",
    "$ref": "#/$defs/root",
    "$defs": {
        "root": {
            "title": "response body",
            "description": "render Sprig template",
            "type": "object",
            "additionalProperties": false,
            "required": [
                "code",
                "msg",
                "data"
            ],
            "properties": {
                "code": {
                    "type": "integer",
                    "description": "status code"
                },
                "msg": {
                    "type": "string",
                    "description": "status message"
                },
                "data": {
                    "type": "string",
                    "description": "the result of rendering the Sprig template"
                }
            }
        }
    }
}