Skip to content

Commit 14b3d83

Browse files
authored
docs: add category-scoped post navigation docs
1 parent 1950510 commit 14b3d83

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

docs/developer-guide/theme/api-changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ title: API 变更日志
33
description: 记录每一个版本的主题 API 变更记录,方便开发者适配
44
---
55

6+
## 2.25.0
7+
8+
### 文章 Finder API > 新增 `cursorByCategory(postName)` 方法
9+
10+
我们为文章 Finder API 新增了 `cursorByCategory(postName)` 方法,用于获取当前文章主分类下的上一篇 / 下一篇文章。主分类为文章 `spec.categories` 中的第一个分类,且只匹配同一分类,不会包含子分类中的文章。
11+
12+
同时,Public API `GET /apis/api.content.halo.run/v1alpha1/posts/{name}/navigation` 新增了可选的 `scope=category` 查询参数,用于获取同一主分类下的文章导航。详细文档可查阅:[文章 Finder API#cursorByCategory](../../developer-guide/theme/finder-apis/post.md#cursorbycategorypostname)
13+
614
## 2.24.1
715

816
### 文章 Finder API > 新增 `random(maxSize)` 方法

docs/developer-guide/theme/finder-apis/post.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,55 @@ postFinder.cursor(postName);
103103
</div>
104104
```
105105

106+
## cursorByCategory(postName)
107+
108+
```js
109+
postFinder.cursorByCategory(postName);
110+
```
111+
112+
### 描述
113+
114+
根据文章的 `metadata.name` 获取同一主分类下相邻的文章(上一篇 / 下一篇)。
115+
116+
主分类为文章 `spec.categories` 中的第一个分类。此方法只匹配同一分类下的文章,不会包含子分类中的文章。如果当前文章没有分类、未发布或者不存在,将返回空的导航结果。
117+
118+
:::info[提示]
119+
上一篇文章是指发布时间较当前文章更早的文章,下一篇文章是指发布时间较当前文章更新的文章。
120+
:::
121+
122+
对应的 Public API 为:
123+
124+
```bash
125+
GET /apis/api.content.halo.run/v1alpha1/posts/{name}/navigation?scope=category
126+
```
127+
128+
### 参数
129+
130+
1. `postName:string` - 文章的唯一标识 `metadata.name`
131+
132+
### 返回值
133+
134+
[#NavigationPostVo](#navigationpostvo)
135+
136+
### 示例
137+
138+
```html title="/templates/post.html"
139+
<div th:with="postCursor = ${postFinder.cursorByCategory(post.metadata.name)}">
140+
<a
141+
th:if="${postCursor.hasPrevious()}"
142+
th:href="@{${postCursor.previous.status.permalink}}"
143+
>
144+
<span th:text="${postCursor.previous.spec.title}"></span>
145+
</a>
146+
<a
147+
th:if="${postCursor.hasNext()}"
148+
th:href="@{${postCursor.next.status.permalink}}"
149+
>
150+
<span th:text="${postCursor.next.spec.title}"></span>
151+
</a>
152+
</div>
153+
```
154+
106155
## listAll()
107156

108157
```js

0 commit comments

Comments
 (0)