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

Commit 8f8b1ad

Browse files
committed
feat: support configuring global pagination
1 parent 3dd3a57 commit 8f8b1ad

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/node/handleOptions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function handleOptions(
2424
options: BlogPluginOptions,
2525
ctx: VuePressContext,
2626
) {
27-
let { directories = [], frontmatters = [] } = options
27+
let { directories = [], frontmatters = [], globalPagination = {} as PaginationConfig } = options
2828

2929
/**
3030
* Validate the existence of directory specified by directory classifier.
@@ -115,6 +115,7 @@ export function handleOptions(
115115
},
116116
...resolvePaginationConfig(
117117
ClassifierTypeEnum.Directory,
118+
globalPagination,
118119
pagination,
119120
indexPath,
120121
ctx,

src/node/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
111111
},
112112
...resolvePaginationConfig(
113113
ClassifierTypeEnum.Frontmatter,
114+
options.globalPagination,
114115
pagination,
115116
indexPath,
116117
ctx,
@@ -215,7 +216,7 @@ function mapToString(map, unstringedKeys: string[] | boolean = []) {
215216
keys === true || (Array.isArray(keys) && keys.includes(key))
216217
? map[key]
217218
: JSON.stringify(map[key])
218-
},\n`
219+
},\n`
219220
}
220221
str += '}'
221222
return str

src/node/interface/Options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ export interface FrontmatterClassifier {
8383
export interface BlogPluginOptions {
8484
directories: DirectoryClassifier[];
8585
frontmatters: FrontmatterClassifier[];
86+
globalPagination: PaginationConfig
8687
}

src/node/util.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ export function logPages(title, pages) {
4040
data.push(
4141
...pages.map(({ // @ts-ignore
4242
path, permalink, meta, pid, id, frontmatter }) => [
43-
// @ts-ignore // @ts-ignore
44-
permalink || path || '',
45-
JSON.stringify(meta) || '',
46-
pid || '',
47-
id || '',
48-
JSON.stringify(frontmatter) || '',
49-
]),
43+
// @ts-ignore // @ts-ignore
44+
permalink || path || '',
45+
JSON.stringify(meta) || '',
46+
pid || '',
47+
id || '',
48+
JSON.stringify(frontmatter) || '',
49+
]),
5050
)
5151
console.log(table(data))
5252
console.log()
@@ -55,6 +55,7 @@ export function logPages(title, pages) {
5555

5656
export function resolvePaginationConfig(
5757
classifierType: ClassifierTypeEnum,
58+
globalPagination = {} as PaginationConfig,
5859
pagination = {} as PaginationConfig,
5960
indexPath,
6061
ctx: VuePressContext,
@@ -86,6 +87,7 @@ export function resolvePaginationConfig(
8687
return prevTime - nextTime > 0 ? -1 : 1
8788
},
8889
},
90+
globalPagination,
8991
pagination,
9092
)
9193
}

0 commit comments

Comments
 (0)