--- title: 文章 description: 文章 - PostFinder --- import CategoryVo from "../vo/_CategoryVo.md"; import TagVo from "../vo/_TagVo.md"; import PostVo from "../vo/_PostVo.md"; import ContentVo from "../vo/_ContentVo.md" import ContributorVo from "../vo/_ContributorVo.md" import ListedPostVo from "../vo/_ListedPostVo.md" ## getByName(postName) ```js postFinder.getByName(postName); ``` ### 描述 根据 `metadata.name` 获取文章。 ### 参数 1. `postName:string` - 文章的唯一标识 `metadata.name`。 ### 返回值 [#PostVo](#postvo) ### 示例 ```html
``` ## content(postName) ```js postFinder.content(postName); ``` ### 描述 根据文章的 `metadata.name` 单独获取文章内容。 ### 参数 1. `postName:string` - 文章的唯一标识 `metadata.name`。 ### 返回值 [#ContentVo](#contentvo) ### 示例 ```html
``` ## cursor(postName) ```js postFinder.cursor(postName); ``` ### 描述 根据文章的 `metadata.name` 获取相邻的文章(上一篇 / 下一篇)。 ### 参数 1. `postName:string` - 文章的唯一标识 `metadata.name`。 ### 返回值 [#NavigationPostVo](#navigationpostvo) ### 示例 ```html title="/templates/post.html"
``` ## listAll() ```js postFinder.listAll(); ``` ### 描述 获取所有文章。 ### 参数 无 ### 返回值 List\<[#ListedPostVo](#listedpostvo)\> ### 示例 ```html ``` ## `list({...})` ```js postFinder.list({ page: 1, size: 10, tagName: 'fake-tag', categoryName: 'fake-category', ownerName: 'fake-owner', sort: {'spec.publishTime,desc', 'metadata.creationTimestamp,asc'} }); ``` ### 描述 统一参数的文章列表查询方法,支持分页、标签、分类、创建者、排序等参数,且均为可选参数。 可以使用此方法来代替 `list(page, size)`、`listByCategory(page, size, categoryName)`、`listByTag(page, size, tag)`、`listByOwner(page, size, owner)` 方法。 ### 参数 1. `page:int` - 分页页码,从 1 开始 2. `size:int` - 分页条数 3. `tagName:string` - 标签唯一标识 `metadata.name` 4. `categoryName:string` - 分类唯一标识 `metadata.name` 5. `ownerName:string` - 创建者用户名 `name` 6. `sort:string[]` - 排序字段,格式为 `字段名,排序方式`,排序方式可选值为 `asc` 或 `desc`,如 `spec.publishTime,desc`,传递时需要使用 `{}` 形式并用逗号分隔表示数组。 ### 返回值 [#ListResult\](#listresultlistedpostvo) ### 示例 ```html ``` ## list(page,size) ```js postFinder.list(page, size); ``` ### 描述 根据分页参数获取文章列表。 **已过时**: 请使用 `list({...})` 方法代替。 ### 参数 1. `page:int` - 分页页码,从 1 开始 2. `size:int` - 分页条数 ### 返回值 [#ListResult\](#listresultlistedpostvo) ### 示例 ```html ``` ## listByCategory(page,size,categoryName) ```js postFinder.listByCategory(page, size, categoryName); ``` ### 描述 根据分类标识和分页参数获取文章列表。 **已过时**: 请使用 `list({...})` 方法代替。 ### 参数 1. `page:int` - 分页页码,从 1 开始 2. `size:int` - 分页条数 3. `categoryName:string` - 文章分类唯一标识 `metadata.name` ### 返回值 [#ListResult\](#listresultlistedpostvo) ### 示例 ```html
``` ## listByTag(page,size,tag) ```js postFinder.listByTag(page, size, tag); ``` ### 描述 根据标签标识和分页参数获取文章列表。 **已过时**: 请使用 `list({...})` 方法代替。 ### 参数 1. `page:int` - 分页页码,从 1 开始 2. `size:int` - 分页条数 3. `tag:string` - 文章分类唯一标识 `metadata.name` ### 返回值 [#ListResult\](#listresultlistedpostvo) ### 示例 ```html
``` ## listByOwner(page,size,owner) ```js postFinder.listByOwner(page, size, owner); ``` ### 描述 根据创建者用户名和分页参数获取文章列表。 **已过时**: 请使用 `list({...})` 方法代替。 ### 参数 1. `page:int` - 分页页码,从 1 开始 2. `size:int` - 分页条数 3. `owner:string` - 创建者用户名 `name` ### 返回值 [#ListResult\](#listresultlistedpostvo) ### 示例 ```html
``` ## archives(page,size) ```js postFinder.archives(page, size); ``` ### 描述 根据分页参数获取文章归档列表。 ### 参数 1. `page:int` - 分页页码,从 1 开始 2. `size:int` - 分页条数 ### 返回值 [#ListResult\](#listresultpostarchivevo) ### 示例 ```html

``` ## archives(page,size,year) ```js postFinder.archives(page, size, year); ``` ### 描述 根据年份和分页参数获取文章归档列表。 ### 参数 1. `page:int` - 分页页码,从 1 开始 2. `size:int` - 分页条数 3. `year:string` - 年份 ### 返回值 [#ListResult\](#listresultpostarchivevo) ### 示例 ```html

``` ## archives(page,size,year,month) ```js postFinder.archives(page, size, year, month); ``` ### 描述 根据年月和分页参数获取文章归档列表。 ### 参数 1. `page:int` - 分页页码,从 1 开始 2. `size:int` - 分页条数 3. `year:string` - 年份 4. `month:string` - 月份 ### 返回值 [#ListResult\](#listresultpostarchivevo) ### 示例 ```html

``` ## 类型定义 ### CategoryVo ### TagVo ### ContributorVo ### PostVo - [#CategoryVo](#categoryvo) - [#TagVo](#tagvo) - [#ContributorVo](#contributorvo) - [#ContentVo](#contentvo) ### ContentVo ### NavigationPostVo ```json title="NavigationPostVo" { "previous": "#PostVo", // 上一篇文章 "current": "#PostVo", // 当前文章 "next": "#PostVo" // 下一篇文章 } ``` - [#PostVo](#postvo) ### ListedPostVo - [#CategoryVo](#categoryvo) - [#TagVo](#tagvo) - [#ContributorVo](#contributorvo) ### ListResult\ ```json title="ListResult" { "page": 0, // 当前页码 "size": 0, // 每页条数 "total": 0, // 总条数 "items": "List<#ListedPostVo>", // 文章列表数据 "first": true, // 是否为第一页 "last": true, // 是否为最后一页 "hasNext": true, // 是否有下一页 "hasPrevious": true, // 是否有上一页 "totalPages": 0 // 总页数 } ``` - [#ListedPostVo](#listedpostvo) ### PostArchiveVo ```json title="PostArchiveVo" { "year": "string", "months": [ { "month": "string", "posts": "#ListedPostVo" } ] } ``` - [#ListedPostVo](#listedpostvo) ### ListResult\ ```json title="ListResult" { "page": 0, // 当前页码 "size": 0, // 每页条数 "total": 0, // 总条数 "items": "List<#PostArchiveVo>", // 文章归档数据 "first": true, // 是否为第一页 "last": true, // 是否为最后一页 "hasNext": true, // 是否有下一页 "hasPrevious": true, // 是否有上一页 "totalPages": 0 // 总页数 } ``` - [#PostArchiveVo](#postarchivevo)