Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/pagination/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,28 @@ function getPaginationPageUrl(index) {
- For [frontmatter classifier](../README.md#frontmatter-classifier), the `indexPath` defaults to `/${classifier.pid}/${classifier.id}`
(e.g. `/tag/js/`)

## getPaginationPageTitle

- Type: function
- Default: `See Below`

A function to get the title of pagination page dynamically:

```js
// directories
function getPaginationPageTitle (index, id) {
return `Page ${index + 1} | ${id}`
}

// frontmatters
function getPaginationPageTitle (index, id, scope) {
return `Page ${index + 1} - ${id} | ${scope}`
}
```

There are three args to help you customize your title:
- `index` is the index of pages.
- `id` is the id in the [config](../config/#id).
- `scope` is the [key](../config/#keys) while configuring frontmatters or same as `id` while configuring directories.


2 changes: 1 addition & 1 deletion src/node/handleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function handleOptions(
*/
paginations.push({
classifierType: ClassifierTypeEnum.Directory,
getPaginationPageTitle(index) {
getPaginationPageTitle(index, id) {
return `Page ${index + 1} | ${id}`
},
...resolvePaginationConfig(
Expand Down
4 changes: 2 additions & 2 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {

paginations.push({
classifierType: ClassifierTypeEnum.Frontmatter,
getPaginationPageTitle(index) {
return `Page ${index + 1} - ${key} | ${scope}`
getPaginationPageTitle(index, id, scope) {
return `Page ${index + 1} - ${id} | ${scope}`
},
...resolvePaginationConfig(
ClassifierTypeEnum.Frontmatter,
Expand Down
6 changes: 3 additions & 3 deletions src/node/interface/Pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type PageSorter = (
) => boolean | number

export type GetPaginationPageUrl = (index: number) => string
export type getPaginationPageTitle = (index: number) => string
export type GetPaginationPageTitle = (index: number, id: string, scope: string) => string

/**
* Pagination config options for users.
Expand Down Expand Up @@ -45,7 +45,7 @@ export interface PaginationConfig {
/**
* A function to get the title of pagination page dynamically.
*/
getPaginationPageTitle?: getPaginationPageTitle;
getPaginationPageTitle?: GetPaginationPageTitle;
}

export interface PaginationIdentity {
Expand All @@ -64,7 +64,7 @@ export interface PaginationIdentity {
*/
export interface InternalPagination
extends PaginationConfig,
PaginationIdentity {
PaginationIdentity {
/**
* Record which classfier create this pagination.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/node/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
InternalPagination,
PageFilter,
GetPaginationPageUrl,
getPaginationPageTitle,
GetPaginationPageTitle,
SerializedPagination,
} from './interface/Pagination'
import { logPages } from './util'
Expand Down Expand Up @@ -82,7 +82,7 @@ export async function registerPaginations(
permalink: path,
frontmatter: {
layout,
title: (getPaginationPageTitle as getPaginationPageTitle)(index),
title: (getPaginationPageTitle as GetPaginationPageTitle)(index, id, pid),
},
meta: {
pid,
Expand Down