> 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.

# 文章归档

文章归档页面，用于列出网站的所有文章，如果你编写的主题首页不显示文章列表，那么可以利用这个模板为网站单独提供一个查看文章列表的页面。

## 路由信息

- 模板路径：`/templates/archives.html`
- 访问路径
  - `/archives`
  - `/archives/:year`
  - `/archives/:year/:month`

:::info 路径变量格式
`year` 必须为 4 位数字（如 `2026`），`month` 必须为 2 位数字（如 `08`），不符合格式的路径不会被归档路由匹配。
:::

## 变量

### archives

#### 变量类型

[#UrlContextListResult\<PostArchiveVo>](#urlcontextlistresultpostarchivevo)

#### 示例

```html title="/templates/archives.html"
<th:block th:each="archive : ${archives.items}">
  <h1 th:text="${archive.year}"></h1>
  <ul>
    <th:block th:each="month : ${archive.months}">
      <li th:each="post : ${month.posts}">
        <a th:href="@{${post.status.permalink}}" th:text="${post.spec.title}">
        </a>
      </li>
    </th:block>
  </ul>
</th:block>
<div th:if="${archives.hasPrevious() || archives.hasNext()}">
  <a th:href="@{${archives.prevUrl}}">
    <span>上一页</span>
  </a>
  <span th:text="${archives.page} +' / '+ ${archives.totalPages}"></span>
  <a th:href="@{${archives.nextUrl}}">
    <span>下一页</span>
  </a>
</div>
```

### \_templateId

#### 变量值

`archives`（自 Halo 2.4.0 起可用）

## 类型定义

### CategoryVo

```jsonc title="CategoryVo"
{
  "metadata": {
    "name": "string", // 唯一标识
    "labels": {
      "additionalProp1": "string",
    },
    "annotations": {
      "additionalProp1": "string",
    },
    "creationTimestamp": "2022-11-20T13:06:38.512Z", // 创建时间
  },
  "spec": {
    "displayName": "string", // 显示名称
    "slug": "string", // 别名，通常用于生成 status.permalink
    "description": "string", // 描述
    "cover": "string", // 封面图
    "template": "string", // 自定义渲染模板名称
    "priority": 0, // 排序字段
    "parent": "string", // 父分类的 metadata.name，根分类为空
    "children": [
      // 已弃用，仅用于兼容旧数据，不再表示当前分类层级
      "string",
    ],
  },
  "status": {
    "permalink": "string", // 固定链接
  },
  "postCount": 0, // 文章数量
}
```

### TagVo

```jsonc title="TagVo"
{
  "metadata": {
    "name": "string", // 唯一标识
    "labels": {
      "additionalProp1": "string",
    },
    "annotations": {
      "additionalProp1": "string",
    },
    "creationTimestamp": "2022-11-20T13:06:38.512Z", // 创建时间
  },
  "spec": {
    "displayName": "string", // 显示名称
    "slug": "string", // 别名，通常用于生成 status.permalink
    "color": "#F9fEB1", // 背景颜色
    "cover": "string", // 封面图
  },
  "status": {
    "permalink": "string", // 固定链接
  },
  "postCount": 0, // 文章数量
}
```

### ContributorVo

```jsonc title="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", // 创建时间
  },
}
```

### ListedPostVo

```jsonc title="ListedPostVo"
{
  "metadata": {
    "name": "string", // 唯一标识
    "labels": {
      "additionalProp1": "string",
    },
    "annotations": {
      "additionalProp1": "string",
    },
    "creationTimestamp": "2022-11-20T13:06:38.505Z", // 创建时间
  },
  "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", // 摘要内容
    },
    "categories": [
      // 分类的名称集合，即 Category 的 metadata.name 的集合
      "string",
    ],
    "tags": [
      // 标签的名称集合，即 Tag 的 metadata.name 的集合
      "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",
    ],
  },
  "categories": "List<#CategoryVo>", // 分类的集合
  "tags": "List<#TagVo>", // 标签的集合
  "contributors": "List<#ContributorVo>", // 贡献者的集合
  "owner": "#ContributorVo", // 创建者
  "stats": {
    "visit": 0, // 访问数量
    "upvote": 0, // 点赞数量
    "comment": 0, // 评论数量
  },
}
```

- [#CategoryVo](#categoryvo)
- [#TagVo](#tagvo)
- [#ContributorVo](#contributorvo)

### PostArchiveVo

```jsonc title="PostArchiveVo"
{
  "year": "string", // 年份
  "months": [
    // 按月的文章集合
    {
      "month": "string", // 月份
      "posts": "List<#ListedPostVo>", // 文章列表数据
    },
  ],
}
```

- [#ListedPostVo](#listedpostvo)

### UrlContextListResult\<PostArchiveVo>

```jsonc title="UrlContextListResult<PostArchiveVo>"
{
  "page": 0, // 当前页码
  "size": 0, // 每页条数
  "total": 0, // 总条数
  "items": "List<#PostArchiveVo>", // 文章归档数据
  "first": true, // 是否为第一页
  "last": true, // 是否为最后一页
  "hasNext": true, // 是否有下一页
  "hasPrevious": true, // 是否有上一页
  "totalPages": 0, // 总页数
  "nextUrl": "string", // 下一页链接
  "prevUrl": "string", // 上一页链接
}
```

- [#PostArchiveVo](#postarchivevo)
