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

Commit

Permalink
feat: support configuring pagination link text
Browse files Browse the repository at this point in the history
  • Loading branch information
billyyyyy3320 committed Jan 10, 2020
1 parent 8629042 commit c3d8065
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
14 changes: 14 additions & 0 deletions docs/pagination/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ The function will be a parameter of [Array.sort()](https://developer.mozilla.org
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.
:::

## prevText

- Type: string
- Default: `Prev`

Text for previous links.

## nextText

- Type: string
- Default: `Next`

Text for next links.

## lengthPerPage

- Type: number
Expand Down
4 changes: 2 additions & 2 deletions src/client/components/Pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
:value="page"
:page-count="$pagination.length"
:click-handler="clickCallback"
:prev-text="'Prev'"
:next-text="'Next'"
:prev-text="$pagination.prevText"
:next-text="$pagination.nextText"
:container-class="'pagination'"
:page-class="'page-item'"
>
Expand Down
12 changes: 6 additions & 6 deletions src/client/components/SimplePagination.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<div class="pagination simple-pagination">
<router-link v-if="$pagination.hasPrev" :to="$pagination.prevLink"
>Prev</router-link
>
<router-link v-if="$pagination.hasNext" :to="$pagination.nextLink"
>Next</router-link
>
<router-link v-if="$pagination.hasPrev" :to="$pagination.prevLink">
{{ $pagination.prevText }}
</router-link>
<router-link v-if="$pagination.hasNext" :to="$pagination.nextLink">
{{ $pagination.nextText }}
</router-link>
</div>
</template>

Expand Down
17 changes: 16 additions & 1 deletion src/client/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ class Pagination {

public _indexPage: string;

private _prevText: string;

private _nextText: string;

constructor(pagination, pages, route) {
debug('pagination', pagination);
const { pages: paginationPages } = pagination;
const { pages: paginationPages, prevText, nextText } = pagination;
const { path } = route;

this._prevText = prevText;
this._nextText = nextText;

for (let i = 0, l = paginationPages.length; i < l; i++) {
const page = paginationPages[i];
if (page.path === path) {
Expand Down Expand Up @@ -78,6 +85,14 @@ class Pagination {
return null;
}

get prevText() {
return this._prevText;
}

get nextText() {
return this._nextText;
}

getSpecificPageLink(index) {
return this._paginationPages[index].path;
}
Expand Down
15 changes: 13 additions & 2 deletions src/node/interface/Pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type GetPaginationPageTitle = (
/**
* Pagination config options for users.
*/
export interface PaginationConfig {
export interface PaginationConfig extends Partial<LinkText> {
/**
* Filter for matched pages.
*/
Expand Down Expand Up @@ -78,7 +78,7 @@ export interface InternalPagination
/**
* Serialized pagination, generated for front-end use
*/
export interface SerializedPagination extends PaginationIdentity {
export interface SerializedPagination extends PaginationIdentity, LinkText {
/**
* Stringified filter function
*/
Expand All @@ -93,6 +93,17 @@ export interface SerializedPagination extends PaginationIdentity {
pages: PaginationPage[];
}

interface LinkText {
/**
* Text for previous links.
*/
prevText: string;
/**
* Text for next links.
*/
nextText: string;
}

/**
* Auto-generated pagination page
*/
Expand Down
4 changes: 4 additions & 0 deletions src/node/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export async function registerPaginations(
sorter,
layout,
lengthPerPage,
prevText = 'Prev',
nextText = 'Next',
getPaginationPageUrl,
getPaginationPageTitle,
} of paginations) {
Expand All @@ -74,6 +76,8 @@ export async function registerPaginations(
const path = (getPaginationPageUrl as GetPaginationPageUrl)(index);
return { path, interval };
}),
prevText,
nextText,
};

recordPageFilters(pid, filter);
Expand Down

0 comments on commit c3d8065

Please sign in to comment.