Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit de1d61a

Browse files
committed
fix: cannot filter correct pages for frontmatter classifier
1 parent 3213ffa commit de1d61a

File tree

6 files changed

+18
-23
lines changed

6 files changed

+18
-23
lines changed

src/client/pagination.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class Pagination {
3535

3636
this._paginationPages = paginationPages
3737
this._currentPage = paginationPages[this.paginationIndex]
38-
this._matchedPages = pages.filter(pagination.filter).sort(pagination.sorter)
38+
this._matchedPages = pages
39+
.filter(page => pagination.filter(page, pagination.id, pagination.pid))
40+
.sort(pagination.sorter)
3941
}
4042

4143
setIndexPage(path) {

src/node/handleOptions.ts

-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ export function handleOptions(
9898
ClassifierTypeEnum.Directory,
9999
pagination,
100100
indexPath,
101-
id,
102-
id,
103101
ctx,
104102
),
105103
pid: id,

src/node/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
113113
ClassifierTypeEnum.Frontmatter,
114114
pagination,
115115
indexPath,
116-
scope,
117-
key,
118116
ctx,
119117
keys,
120118
),

src/node/interface/Pagination.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
import { VuePressPage } from './VuePress'
55
import { ClassifierTypeEnum } from './Classifier'
66

7-
export type PageFilter = (page: VuePressPage) => boolean
7+
export type PageFilter = (
8+
page: VuePressPage,
9+
id: string,
10+
pid: string,
11+
) => boolean
12+
813
export type PageSorter = (
914
prev: VuePressPage,
1015
next: VuePressPage,
1116
) => boolean | number
17+
1218
export type GetPaginationPageUrl = (index: number) => string
1319
export type getPaginationPageTitle = (index: number) => string
1420

src/node/pagination.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function registerPaginations(
5858
getPaginationPageTitle,
5959
} of paginations) {
6060
const { pages: sourcePages } = ctx
61-
const pages = sourcePages.filter(filter as PageFilter)
61+
const pages = sourcePages.filter(page => (filter as PageFilter)(page, id, pid))
6262

6363
const intervallers = getIntervallers(pages.length, lengthPerPage)
6464
const pagination: SerializedPagination = {

src/node/util.ts

+7-16
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ export function resolvePaginationConfig(
5656
classifierType: ClassifierTypeEnum,
5757
pagination = {} as PaginationConfig,
5858
indexPath,
59-
pid, // post / tag
60-
id, // post / js
6159
ctx: VuePressContext,
6260
keys: string[] = [''], // ['js']
6361
) {
@@ -76,8 +74,10 @@ export function resolvePaginationConfig(
7674

7775
filter:
7876
classifierType === ClassifierTypeEnum.Directory
79-
? getIdentityFilter(pid, id)
80-
: getFrontmatterClassifierPageFilter(keys, id),
77+
? function(page, id, pid) {
78+
return page.pid === pid && page.id === id
79+
}
80+
: getFrontmatterClassifierPageFilter(keys),
8181

8282
sorter: (prev: VuePressPage, next: VuePressPage) => {
8383
const prevTime = new Date(prev.frontmatter.date).getTime()
@@ -89,22 +89,13 @@ export function resolvePaginationConfig(
8989
)
9090
}
9191

92-
function getIdentityFilter(pid, id) {
93-
return new Function(
94-
'page',
95-
`return page.pid === ${JSON.stringify(pid)} && page.id === ${JSON.stringify(
96-
id,
97-
)}`,
98-
)
99-
}
100-
101-
function getFrontmatterClassifierPageFilter(keys, value) {
92+
function getFrontmatterClassifierPageFilter(keys) {
10293
return new Function(
10394
// @ts-ignore
104-
'page',
95+
'page', 'id', 'pid',
10596
`
10697
const keys = ${JSON.stringify(keys)};
107-
const value = ${JSON.stringify(value)};
98+
const value = id;
10899
return keys.some(key => {
109100
const _value = page.frontmatter[key]
110101
if (Array.isArray(_value)) {

0 commit comments

Comments
 (0)