feat(plugin-blog-data): add page filters

This commit is contained in:
pengzhanbo 2023-02-15 03:54:04 +08:00
parent 06144f8704
commit a15d067d9b
2 changed files with 6 additions and 0 deletions

View File

@ -31,6 +31,9 @@ export const preparedBlogData = async (
let pages = app.pages.filter((page) => {
return page.filePathRelative && pageFilter(page.filePathRelative)
})
if (options.pageFilter) {
pages = pages.filter(options.pageFilter)
}
if (options.sortBy) {
pages = pages.sort((prev, next) => {
if (options.sortBy === 'createTime') {

View File

@ -1,9 +1,12 @@
import type { Page } from '@vuepress/core'
export interface BlogDataPluginOptions {
include?: string | string[]
exclude?: string | string[]
sortBy?: 'createTime' | false | (<T>(prev: T, next: T) => boolean)
excerpt?: boolean
extendBlogData?: <T = any>(page: T) => Record<string, any>
pageFilter?: (page: Page) => boolean
}
export type BlogPostData<T extends object = object> = BlogPostDataItem<T>[]