# Pagination Config

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:

sorter: (prev, next) => {
  const dayjs = require('dayjs');
  const prevTime = dayjs(prev.frontmatter.date);
  const nextTime = dayjs(next.frontmatter.date);
  return prevTime - nextTime > 0 ? -1 : 1;
}

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

Note

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. dayjs accepts this two different result, whereas new Date won't work fine in some browser (e.g. Safari).

# prevText

  • Type: string
  • Default: Prev

Text for previous links.

# nextText

  • Type: string
  • Default: Next

Text for next links.

# 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 (pageNumber) {
  return `Page ${pageNumber} | ${entryTitle}`
}

// frontmatters
function getPaginationPageTitle (pageNumber, key) {
  return `Page ${pageNumber} - ${key} | ${entryTitle}`
}

There are two args to help you customize your title:

  • pageNumber
  • key : the key while configuring frontmatters