@delmaredigital/payload-page-tree

中文文档
0.4.1发布于 2026/11/10MITTypeScriptES Module构建来源已验证近 30 天下载 2355

Payload CMS plugin for folder-based hierarchical URL slugs with visual tree management

原始使用文档
文档目录7 节
  1. Installation
  2. Quick Start
  3. 1. Add the plugin
  4. 2. Define your collection
  5. 3. Frontend routing
  6. Access control
  7. License

@delmaredigital/payload-page-tree

A Payload CMS plugin that extends the built-in folders feature to auto-generate hierarchical URL slugs. Folders define URL structure, pages pick a folder, and slugs are auto-generated.

Starter Template - Use This

Deploy with Vercel

Ask DeepWiki

Documentation: plugins.delmaredigital.com/docs/page-tree · Overview

Installation

pnpm add @delmaredigital/payload-page-tree

Quick Start

1. Add the plugin

// src/payload.config.ts
import { buildConfig } from 'payload'
import { pageTreePlugin } from '@delmaredigital/payload-page-tree'
import { Pages } from './collections/Pages'

export default buildConfig({
  collections: [Pages],
  plugins: [
    pageTreePlugin(),  // Auto-detects 'pages' and 'posts' if they exist
  ],
})

2. Define your collection

Your collections must have a slug field. The plugin makes it read-only and auto-generates values from folder path + page segment.

// src/collections/Pages/index.ts
import type { CollectionConfig } from 'payload'

export const Pages: CollectionConfig = {
  slug: 'pages',
  fields: [
    { name: 'title', type: 'text', required: true },
    {
      name: 'slug',
      type: 'text',
      required: true,
      unique: true,
      index: true,
    },
  ],
}

Important: Do NOT use Payload's slugField() helper. Use a plain text field — the plugin manages slugs via its own hooks.

3. Frontend routing

// app/[...slug]/page.tsx
export default async function Page({ params }: { params: { slug: string[] } }) {
  const fullSlug = params.slug.join('/')

  const { docs } = await payload.find({
    collection: 'pages',
    where: { slug: { equals: fullSlug } },
    limit: 1,
  })

  // ...
}

That's it! The plugin adds folder, pageSegment, sortOrder, and slugHistory fields automatically, and registers the tree view at /admin/page-tree.


Access control

The tree view calls fourteen endpoints under /api/page-tree/*. Two layers decide who may use them:

  1. Endpoint gate — the access option runs before every endpoint. By default it requires an authenticated Payload user (401 without a user, 403 when denied).
  2. Collection access rules — reads and writes on the documents a user operates on run with overrideAccess: false as the requesting user, so the access rules on your page and folder collections are enforced. URL maintenance (slug ancestry, collision checks, cascade inventories) reads with trusted access, but only beneath folders the user can read. See access control for the details.
pageTreePlugin({
  // Only admins may use the tree endpoints
  access: ({ req }) => req.user?.role === 'admin',
})

Upgrading from 0.3.16 or earlier: those versions registered the endpoints with no authentication and bypassed collection access rules. Upgrade, and review the access rules on your page and folder collections — they now govern the tree. See the CHANGELOG.

License

MIT

版本与发布记录

@delmaredigital/payload-page-tree 共发布 24 个版本,首次发布于 2026/01/11;过去 12 个月发布了 24 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.1latest2026/11/103 天前
0.4.02026/11/093 天前
0.3.182026/11/085 天前
0.3.172026/09/092 个月前
0.3.162026/06/075 个月前
0.3.152026/06/075 个月前

关于 @delmaredigital/payload-page-tree 的常见问题

@delmaredigital/payload-page-tree 是什么?

Payload CMS plugin for folder-based hierarchical URL slugs with visual tree management

如何安装 @delmaredigital/payload-page-tree?

在项目目录运行 npm install @delmaredigital/payload-page-tree,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:next(>=14.0.0 || >=15.0.0 || >=16.0.0)、react(>=18.0.0 || >=19.0.0)、payload(>=3.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@delmaredigital/payload-page-tree 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@delmaredigital/payload-page-tree 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@delmaredigital/payload-page-tree 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^18.20.2 || >=20.9.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@delmaredigital/payload-page-tree 可以商用吗?

@delmaredigital/payload-page-tree 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@delmaredigital/payload-page-tree 的下载量有多少?

根据 npm 官方下载统计,@delmaredigital/payload-page-tree 在 2026/10/12 – 2026/11/10 这 30 天内被下载 2,355 次,日均约 79 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@delmaredigital/payload-page-tree 还在维护吗?

最新版本 0.4.1 发布于 2026/11/10(3 天前);至今共发布 24 个版本,其中过去 12 个月发布了 24 个;首次发布于 2026/01/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。