Returns a flat NodeData[] of every navigable page node (where type === 'page' or a folder where href !== undefined). The primary use case is generating sitemaps and feed files.

import { getPageNodes } from 'slugtree'

const pages = getPageNodes()

Return value

Returns NodeData[] containing only navigable page-like entries. The order matches the tree traversal order from getAllNodes().

Usage

Generating a sitemap in Next.js

import { getPageNodes } from 'slugtree'

export default function sitemap() {
  return getPageNodes().map((page) => ({
    url: `https://example.com${page.href}`,
    lastModified: new Date()
  }))
}

Counting pages

import { getPageNodes } from 'slugtree'

const pageCount = getPageNodes().length

For all nodes including pure folders, use getAllNodes(). For custom filtering conditions, use findNodes(). For client components, use usePageNodes().