Find Neighbours

Find the neighbours of a page from the page tree

Find the neighbours of a page from the page tree, it returns the next and previous page of a given page. It is useful for implementing a footer.

For example:

Quick Startnext: Installation
Installationprevious: Quick Start, next: Concepts
Conceptsprevious: Installation

Usage

It requires a page tree and the url of page.

import { getPageUrl } from 'next-docs-zeta/contentlayer'
import { findNeighbour } from 'next-docs-zeta/server'
 
const url = getPageUrl(params.slug.split('/'), '/docs')
const neighbours = findNeighbour(tree, url)
ParameterTypeDescription
treePageTreeThe page tree
urlstringThe url of page

Last updated on