文章分类
getByName(name)
categoryFinder.getByName(name)
描述
根据 metadata.name 获取文章分类。
参数
- name:string- 分类的唯一标识- metadata.name。
返回值
示例
<div th:with="category = ${categoryFinder.getByName('category-foo')}">
  <a th:href="@{${category.status.permalink}}" th:text="${category.spec.displayName}"></a>
</div>
getByNames(names)
categoryFinder.getByNames(names)
描述
根据一组 metadata.name 获取文章分类。
参数
- names:List<string>- 分类的唯一标识- metadata.name的集合。
返回值
List<#CategoryVo>
示例
<div th:with="categories = ${categoryFinder.getByNames(['category-foo', 'category-bar'])}">
  <a th:each="category : ${categories}" th:href="@{${category.status.permalink}}" th:text="${category.spec.displayName}"></a>
</div>
list(page,size)
categoryFinder.list(page,size)
描述
根据分页参数获取分类列表。
参数
- page:int- 分页页码,从 1 开始
- size:int- 分页条数
返回值
示例
<ul th:with="categories = ${categoryFinder.list(1,10)}">
  <li th:each="category : ${categories.items}">
    <a th:href="@{${category.status.permalink}}" th:text="${category.spec.displayName}"></a>
  </li>
</ul>
listAll()
categoryFinder.listAll()
描述
获取所有文章分类。
参数
无
返回值
List<#CategoryVo>
示例
<ul th:with="categories = ${categoryFinder.listAll()}">
  <li th:each="category : ${categories}">
    <a th:href="@{${category.status.permalink}}" th:text="${category.spec.displayName}"></a>
  </li>
</ul>
listAsTree()
categoryFinder.listAsTree()
描述
获取所有文章分类的多层级结构。
参数
无
返回值
List<#CategoryTreeVo>
示例
<div th:with="categories = ${categoryFinder.listAsTree()}">
  <ul>
    <li th:replace="~{modules/category-tree :: single(categories=${categories})}" />
  </ul>
</div>
/templates/category-tree.html
<ul th:fragment="next (categories)">
  <li th:fragment="single (categories)" th:each="category : ${categories}">
    <a th:href="@{${category.status.permalink}}">
      <span th:text="${category.spec.displayName}"> </span>
    </a>
    <th:block th:if="${not #lists.isEmpty(category.children)}">
      <th:block th:replace="~{modules/category-tree :: next (categories=${category.children})}"></th:block>
    </th:block>
  </li>
</ul>
类型定义
CategoryVo
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,                                      // 排序字段
    "children": [                                       // 下级分类,分类的 metadata.name 集合
      "string"
    ]
  },
  "status": {
    "permalink": "string",                              // 固定链接
    "postCount": 0,                                     // 文章数
    "visiblePostCount": 0                               // 已发布文章数
  },
  "postCount": 0
}
ListResult<CategoryVo>
ListResult<CategoryVo>
{
  "page": 0,                                   // 当前页码
  "size": 0,                                   // 每页条数
  "total": 0,                                  // 总条数
  "items": "List<#CategoryVo>",                // 分类列表数据
  "first": true,                               // 是否为第一页
  "last": true,                                // 是否为最后一页
  "hasNext": true,                             // 是否有下一页
  "hasPrevious": true,                         // 是否有上一页
  "totalPages": 0                              // 总页数
}
CategoryTreeVo
CategoryTreeVo
{
  "metadata": {
    "name": "string",                                   // 唯一标识
    "labels": {
      "additionalProp1": "string"
    },
    "annotations": {
      "additionalProp1": "string"
    },
    "creationTimestamp": "2022-11-20T14:18:49.230Z",    // 创建时间
  },
  "spec": {
    "displayName": "string",                            // 显示名称
    "slug": "string",                                   // 别名,通常用于生成 status.permalink
    "description": "string",                            // 描述
    "cover": "string",                                  // 封面图
    "template": "string",                               // 自定义渲染模板名称
    "priority": 0,                                      // 排序字段
    "children": [                                       // 下级分类,分类的 metadata.name 集合
      "string"
    ]
  },
  "status": {
    "permalink": "string",                              // 固定链接
    "postCount": 0,                                     // 文章数
    "visiblePostCount": 0                               // 已发布文章数
  },
  "children": "List<#CategoryTreeVo>",                  // 下级分类,CategoryTreeVo 的集合
  "parentName": "string",
  "postCount": 0
}