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

Commit 586bf14

Browse files
fix: generate pagination title correctly (fix: #41) (#42)
* fix: generate pagination title correctly * docs: add a tip for getPaginationPageTitle
1 parent cc09e81 commit 586bf14

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

docs/pagination/README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ A function to get the title of pagination page dynamically:
6969
```js
7070
// directories
7171
function getPaginationPageTitle (index, id) {
72-
return `Page ${index + 1} | ${id}`
72+
return `Page ${index + 2} | ${id}`
7373
}
7474

7575
// frontmatters
7676
function getPaginationPageTitle (index, id, scope) {
77-
return `Page ${index + 1} - ${id} | ${scope}`
77+
return `Page ${index + 2} - ${id} | ${scope}`
7878
}
7979
```
8080

@@ -83,4 +83,9 @@ There are three args to help you customize your title:
8383
- `id` is the id in the [config](../config/#id).
8484
- `scope` is the [key](../config/#keys) while configuring frontmatters or same as `id` while configuring directories.
8585

86+
::: tip TIP
87+
`${index + 2}`: why `+2`?
8688

89+
Plus 1 since index starts at 0. <br>
90+
Plus another 1 since the index page won't show page number.
91+
:::

src/node/handleOptions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function handleOptions(
109109
paginations.push({
110110
classifierType: ClassifierTypeEnum.Directory,
111111
getPaginationPageTitle(index, id) {
112-
return `Page ${index + 1} | ${id}`
112+
return `Page ${index + 2} | ${id}`
113113
},
114114
...resolvePaginationConfig(
115115
ClassifierTypeEnum.Directory,

src/node/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
136136
paginations.push({
137137
classifierType: ClassifierTypeEnum.Frontmatter,
138138
getPaginationPageTitle(index, id, scope) {
139-
return `Page ${index + 1} - ${id} | ${scope}`
139+
return `Page ${index + 2} - ${id} | ${scope}`
140140
},
141141
...resolvePaginationConfig(
142142
ClassifierTypeEnum.Frontmatter,

0 commit comments

Comments
 (0)