For AI agents: the complete documentation index is available at https://docs.halo.run/llms.txt, the full documentation bundle is available at https://docs.halo.run/llms-full.txt, and this page is available as Markdown at https://docs.halo.run/developer-guide/theme/template-variables/page.md.

单页面

页面与文章类似,同样包含页面标题和富文本形式的页面内容。与文章不同的是页面无法设置所属分类和标签信息,一般用于站点中单一展示功能的页面,例如常见的站点关于页面、联系我们页面等。

路由信息

  • 模板路径:/templates/page.html
  • 访问路径:/:slug

自定义模板

除了上面提到的 page.html,主题作者还可以添加多种形式的额外渲染模板,提供给用户选择,此举可以丰富网站的使用类型。

定义方式为:

theme.yaml
customTemplates:
  page:
    - name: {name}
      description: {description}
      screenshot: {screenshot}
      file: {file}.html
  • name:模板名称
  • description:模板描述
  • screenshot:模板预览图
  • file:模板文件名,需要在 /templates/ 目录下创建

示例:

theme.yaml
customTemplates:
  page:
    - name: 关于公司
      description: 用于展示公司的一些信息
      screenshot:
      file: page_about.html
修改 theme.yaml 后重载配置

需要注意,修改 theme.yaml 需要重载主题配置

变量

singlePage

变量类型

#SinglePageVo

示例

/templates/page.html
<article>
  <h1 th:text="${singlePage.spec.title}"></h1>
  <div th:utext="${singlePage.content.content}"></div>
</article>

_templateId

变量值

page

类型定义

SinglePageVo

SinglePageVo
{
  "metadata": {
    "name": "string", // 唯一标识
    "labels": {
      "additionalProp1": "string",
    },
    "annotations": {
      "additionalProp1": "string",
    },
    "creationTimestamp": "2022-11-20T14:29:44.601Z", // 创建时间
  },
  "spec": {
    "title": "string", // 标题
    "slug": "string", // 别名,通常用于生成 status.permalink
    "releaseSnapshot": "string",
    "headSnapshot": "string",
    "baseSnapshot": "string",
    "owner": "string", // 创建者名称,即 ContributorVo 的 metadata.name,非显示名称
    "template": "string", // 自定义渲染模板
    "cover": "string", // 封面图
    "deleted": false,
    "publish": false,
    "publishTime": "2022-11-20T13:06:38.505Z", // 发布时间
    "pinned": false, // 是否置顶
    "allowComment": true, // 是否允许评论
    "visible": "PUBLIC",
    "priority": 0,
    "excerpt": {
      "autoGenerate": true, // 是否自动生成摘要
      "raw": "string", // 摘要内容
    },
    "htmlMetas": [
      {
        "additionalProp1": "string",
      },
    ],
  },
  "status": {
    "permalink": "string", // 固定链接
    "excerpt": "string", // 最终生成的摘要
    "inProgress": true,
    "lastModifyTime": "2022-11-20T13:06:38.505Z", // 最后修改时间
    "commentsCount": 0, // 评论数
    "contributors": [
      // 贡献者名称,Contributor 的 metadata.name 的集合
      "string",
    ],
  },
  "stats": {
    "visit": 0, // 访问数量
    "upvote": 0, // 点赞数量
    "comment": 0, // 评论数量
  },
  "contributors": "List<#ContributorVo>", // 贡献者的集合
  "owner": "#ContributorVo", // 创建者
  "content": "#ContentVo", // 内容
}

ContentVo

ContentVo
{
  "raw": "string", // 原始文本,一般用于给编辑器使用
  "content": "string", // 最终渲染的文本
}

ContributorVo

ContributorVo
{
  "name": "string", // 用户名
  "displayName": "string", // 显示名称
  "avatar": "string", // 头像
  "bio": "string", // 描述
  "permalink": "string", // 作者的文章归档页面链接
  "metadata": {
    "name": "string", // 唯一标识
    "labels": {
      "additionalProp1": "string",
    },
    "annotations": {
      "additionalProp1": "string",
    },
    "creationTimestamp": "2022-11-20T13:06:38.512Z", // 创建时间
  },
}