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

Latest commit

 

History

History
95 lines (69 loc) · 2.47 KB

README.md

File metadata and controls

95 lines (69 loc) · 2.47 KB
sidebar
auto

Pagination Config

::: tip TIP We strongly recommend that you read the Getting Started section before using this plugin. :::

sorter

  • Type: function
  • Default: See Below

Sorter for matched pages, the default sorter is as follows:

function sorter(prev: VuePressPage, next: VuePressPage){
  const prevTime = new Date(prev.frontmatter.date.replace(/\-/g, '/')).getTime()
  const nextTime = new Date(next.frontmatter.date.replace(/\-/g, '/')).getTime()
  return prevTime - nextTime > 0 ? -1 : 1
},

The function will be a parameter of Array.sort().

::: warning Note 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. :::

lengthPerPage

  • Type: number
  • Default: 10

Maximum number of posts per page.

layout

  • Type: string
  • Default: DirectoryPagination || Layout

Layout for pagination page (Except the index page.)

getPaginationPageUrl

  • Type: function
  • Default: See Below

A function to get the url of pagination page dynamically:

function getPaginationPageUrl(index) {
  if (index === 0) {
    return indexPath
  }
  return `${indexPath}page/${index + 1}/`
}

getPaginationPageTitle

  • Type: function
  • Default: See Below

A function to get the title of pagination page dynamically:

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

// frontmatters
function getPaginationPageTitle (index, id, scope) {
  return `Page ${index + 2} - ${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.
  • scope is the key while configuring frontmatters or same as id while configuring directories.

::: warning Note ${index + 2}: why +2?

Plus 1 since index starts at 0.
Plus another 1 since the index page won't show page number. :::