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

Commit c3d8065

Browse files
committed
feat: support configuring pagination link text
1 parent 8629042 commit c3d8065

File tree

6 files changed

+55
-11
lines changed

6 files changed

+55
-11
lines changed

Diff for: docs/pagination/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ The function will be a parameter of [Array.sort()](https://developer.mozilla.org
2828
You might be intrigued by `replace(/\-/g, '/')`. Because only the dates in frontmatter written in 2-digits will be transformed, other dates written in single-digit, such as `2020-1-1` will be treated as string. Some browsers (e.g. Safari) don't support this format.
2929
:::
3030

31+
## prevText
32+
33+
- Type: string
34+
- Default: `Prev`
35+
36+
Text for previous links.
37+
38+
## nextText
39+
40+
- Type: string
41+
- Default: `Next`
42+
43+
Text for next links.
44+
3145
## lengthPerPage
3246

3347
- Type: number

Diff for: src/client/components/Pagination.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
:value="page"
66
:page-count="$pagination.length"
77
:click-handler="clickCallback"
8-
:prev-text="'Prev'"
9-
:next-text="'Next'"
8+
:prev-text="$pagination.prevText"
9+
:next-text="$pagination.nextText"
1010
:container-class="'pagination'"
1111
:page-class="'page-item'"
1212
>

Diff for: src/client/components/SimplePagination.vue

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<template>
22
<div class="pagination simple-pagination">
3-
<router-link v-if="$pagination.hasPrev" :to="$pagination.prevLink"
4-
>Prev</router-link
5-
>
6-
<router-link v-if="$pagination.hasNext" :to="$pagination.nextLink"
7-
>Next</router-link
8-
>
3+
<router-link v-if="$pagination.hasPrev" :to="$pagination.prevLink">
4+
{{ $pagination.prevText }}
5+
</router-link>
6+
<router-link v-if="$pagination.hasNext" :to="$pagination.nextLink">
7+
{{ $pagination.nextText }}
8+
</router-link>
99
</div>
1010
</template>
1111

Diff for: src/client/pagination.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ class Pagination {
1616

1717
public _indexPage: string;
1818

19+
private _prevText: string;
20+
21+
private _nextText: string;
22+
1923
constructor(pagination, pages, route) {
2024
debug('pagination', pagination);
21-
const { pages: paginationPages } = pagination;
25+
const { pages: paginationPages, prevText, nextText } = pagination;
2226
const { path } = route;
2327

28+
this._prevText = prevText;
29+
this._nextText = nextText;
30+
2431
for (let i = 0, l = paginationPages.length; i < l; i++) {
2532
const page = paginationPages[i];
2633
if (page.path === path) {
@@ -78,6 +85,14 @@ class Pagination {
7885
return null;
7986
}
8087

88+
get prevText() {
89+
return this._prevText;
90+
}
91+
92+
get nextText() {
93+
return this._nextText;
94+
}
95+
8196
getSpecificPageLink(index) {
8297
return this._paginationPages[index].path;
8398
}

Diff for: src/node/interface/Pagination.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type GetPaginationPageTitle = (
2525
/**
2626
* Pagination config options for users.
2727
*/
28-
export interface PaginationConfig {
28+
export interface PaginationConfig extends Partial<LinkText> {
2929
/**
3030
* Filter for matched pages.
3131
*/
@@ -78,7 +78,7 @@ export interface InternalPagination
7878
/**
7979
* Serialized pagination, generated for front-end use
8080
*/
81-
export interface SerializedPagination extends PaginationIdentity {
81+
export interface SerializedPagination extends PaginationIdentity, LinkText {
8282
/**
8383
* Stringified filter function
8484
*/
@@ -93,6 +93,17 @@ export interface SerializedPagination extends PaginationIdentity {
9393
pages: PaginationPage[];
9494
}
9595

96+
interface LinkText {
97+
/**
98+
* Text for previous links.
99+
*/
100+
prevText: string;
101+
/**
102+
* Text for next links.
103+
*/
104+
nextText: string;
105+
}
106+
96107
/**
97108
* Auto-generated pagination page
98109
*/

Diff for: src/node/pagination.ts

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export async function registerPaginations(
5353
sorter,
5454
layout,
5555
lengthPerPage,
56+
prevText = 'Prev',
57+
nextText = 'Next',
5658
getPaginationPageUrl,
5759
getPaginationPageTitle,
5860
} of paginations) {
@@ -74,6 +76,8 @@ export async function registerPaginations(
7476
const path = (getPaginationPageUrl as GetPaginationPageUrl)(index);
7577
return { path, interval };
7678
}),
79+
prevText,
80+
nextText,
7781
};
7882

7983
recordPageFilters(pid, filter);

0 commit comments

Comments
 (0)