@justanarthur/payload-www 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,7 +11,7 @@ language switcher share a single source of truth with the rest of your app.
11
11
 
12
12
  - **Composer** — `createWWWConfig({ locales, blocks, defaultPlugins? })` returns `{ withWWWConfig }`. One composer call is enough for the most common cases.
13
13
  - **Collections** — `Pages` (title, blocks tab, slug, drafts, revalidation hook), `Posts` (title, excerpt, richText, drafts, revalidation hook), `StaticPages` (system pages — 404, 500, search-empty, … — addressed by a `kind` discriminator, not a slug)
14
- - **Globals** — `Header` and `Footer` (both `nav` blocks with `navColumn` / `navItem`)
14
+ - **Globals** — `Header` and `Footer` (both `nav` blocks with `navColumn` / `navItem`). Extend the nav link schema (e.g. a `description` or a `navHover` mega-menu group) via `createHeaderGlobal({ navColumnLinkFields, navItemLinkFields })` / `createFooterGlobal({ … })`, or `link({ extraFields })` directly.
15
15
  - **Default render components** — `PagesPage`, `HeaderPage`, `FooterPage` Server Components. Override any of them by setting a different `custom.path` on the collection / global.
16
16
  - **LivePreviewListener** — built in. The lib's `createCollectionPageExports` default page renders it (via `React.lazy` so the server dist stays free of `'use client'` imports) whenever Next.js draft mode is on. Hosts get live preview automatically — no opt-in required. The component itself is also exported from `/render-components` for hosts that want to mount it elsewhere.
17
17
  - **Hooks** — `createRevalidateCollectionHook(opts)` (canonical factory for **all** collections: Pages, Posts, host-defined; per-locale `revalidatePath` fan-out + `revalidateTag('collection_<slug>_<id>', 'max')` + sitemap tag, with a `pathMode: 'tag-only'` mode for collections without a URL like `staticPages`), `createRevalidatePageHooks()` (deprecated alias for Pages preset), `createRevalidateGlobalHook(slug)` (per-locale tag for globals)
@@ -308,6 +308,7 @@ Subpath imports:
308
308
  | `blocks` | `Block[]` | yes | Blocks the Pages collection accepts. |
309
309
  | `linkRelationTo` | `string[]` | no | Collection slugs the Header / Footer nav links can reference. Default: `['pages']`. |
310
310
  | `registerPosts` | `boolean` | no | Register the lib's Posts collection. Default `true`. |
311
+ | `nested` | `boolean` | no | Enable nested Pages slugs (`about_us` → `/about/us`). Relaxes the Pages slug validation to accept the `_` divider. Pass the same `nested: true` to `createCollectionPageExports` on the Pages route (and `nested: { pages: true }` to `createSitemapFile`). Default `false`. |
311
312
  | StaticPages | — | yes | Always registered (every site has 404). Hosts filter it out in `collections:` to opt. |
312
313
  | `defaultPlugins` | `(defaults: Plugin[]) => Plugin[]`| no | Final say on the default `[seoPlugin, imageHashPlugin, translator]` list. |
313
314
 
@@ -76,6 +76,14 @@ type CreatePagesCollectionOptions = {
76
76
  * when omitted.
77
77
  */
78
78
  defaultLocale?: CreateRevalidateCollectionHookOptions["defaultLocale"];
79
+ /**
80
+ * Enable nested (hierarchical) slugs. When `true`, the slug field
81
+ * additionally accepts the `_` nesting divider (so `about_us`
82
+ * renders at `/about/us`) and the admin description documents the
83
+ * convention. Pair with `createCollectionPageExports({ nested: true })`
84
+ * on the matching route. Default: `false` (flat, hyphen-only slugs).
85
+ */
86
+ nested?: boolean;
79
87
  };
80
88
  declare const createPagesCollection: (blocks: Block[], options?: Omit<CreatePagesCollectionOptions, "blocks">) => CollectionConfig;
81
89
  import { CollectionConfig as CollectionConfig2 } from "payload";
@@ -134,7 +142,7 @@ type CreateStaticPagesCollectionOptions = {
134
142
  blocks: Block2[];
135
143
  };
136
144
  declare const createStaticPagesCollection: (blocks: Block2[]) => CollectionConfig3;
137
- import { GlobalConfig } from "payload";
145
+ import { Field, GlobalConfig } from "payload";
138
146
  type CreateHeaderGlobalOptions = {
139
147
  /**
140
148
  * Optional override for the `custom.path` Payload uses to resolve
@@ -148,6 +156,17 @@ type CreateHeaderGlobalOptions = {
148
156
  * different list when your host has additional linkable collections.
149
157
  */
150
158
  linkRelationTo?: string[];
159
+ /**
160
+ * Extra fields appended to each `navColumn` link — e.g. a
161
+ * `description` text field or a `navHover` group for a mega-menu.
162
+ * Lets hosts enrich the column-link schema without redefining the
163
+ * whole nav.
164
+ */
165
+ navColumnLinkFields?: Field[];
166
+ /**
167
+ * Extra fields appended to each top-level `navItem` link.
168
+ */
169
+ navItemLinkFields?: Field[];
151
170
  };
152
171
  /**
153
172
  * Build the Header global. The lib's default shape: a `nav` blocks
@@ -155,7 +174,7 @@ type CreateHeaderGlobalOptions = {
155
174
  * and `navItem` (a single link).
156
175
  */
157
176
  declare const createHeaderGlobal: (options?: CreateHeaderGlobalOptions) => GlobalConfig;
158
- import { GlobalConfig as GlobalConfig2 } from "payload";
177
+ import { Field as Field2, GlobalConfig as GlobalConfig2 } from "payload";
159
178
  type CreateFooterGlobalOptions = {
160
179
  /**
161
180
  * Optional override for the `custom.path` Payload uses to resolve
@@ -169,6 +188,16 @@ type CreateFooterGlobalOptions = {
169
188
  * different list when your host has additional linkable collections.
170
189
  */
171
190
  linkRelationTo?: string[];
191
+ /**
192
+ * Extra fields appended to each `navColumn` link — e.g. a
193
+ * `description` text field. Lets hosts enrich the column-link
194
+ * schema without redefining the whole nav.
195
+ */
196
+ navColumnLinkFields?: Field2[];
197
+ /**
198
+ * Extra fields appended to each top-level `navItem` link.
199
+ */
200
+ navItemLinkFields?: Field2[];
172
201
  };
173
202
  /**
174
203
  * Build the Footer global. The lib's default shape mirrors the
@@ -23,7 +23,6 @@ var authenticatedOrPublished = ({ req: { user } }) => {
23
23
  return true;
24
24
  return { _status: { equals: "published" } };
25
25
  };
26
-
27
26
  // src/render/_locale.ts
28
27
  function prefixFor(locale, defaultLocale, mode) {
29
28
  if (mode === "never")
@@ -195,24 +194,9 @@ var createPagesCollection = (blocks, options = {}) => {
195
194
  renderPath = PAGES_RENDER_PATH,
196
195
  slug: collectionSlug = PAGES_SLUG2,
197
196
  localePrefix,
198
- defaultLocale
197
+ defaultLocale,
198
+ nested = false
199
199
  } = options;
200
- const slugField = {
201
- name: "slug",
202
- type: "text",
203
- required: true,
204
- unique: true,
205
- index: true,
206
- admin: { position: "sidebar" },
207
- validate: (value) => {
208
- if (typeof value !== "string")
209
- return "Slug must be a string";
210
- if (value !== "" && !/^[a-z0-9-]+$/.test(value)) {
211
- return "Slug must be lowercase, with hyphens (no spaces or special characters)";
212
- }
213
- return true;
214
- }
215
- };
216
200
  const baseFields = [
217
201
  {
218
202
  name: "title",
@@ -242,7 +226,7 @@ var createPagesCollection = (blocks, options = {}) => {
242
226
  type: "date",
243
227
  admin: { position: "sidebar" }
244
228
  },
245
- slugField
229
+ slugField({ nested })
246
230
  ];
247
231
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
248
232
  collectionSlug,
@@ -277,14 +261,6 @@ var createPostsCollection = (options = {}) => {
277
261
  localePrefix,
278
262
  defaultLocale
279
263
  } = options;
280
- const slugField = {
281
- name: "slug",
282
- type: "text",
283
- required: true,
284
- unique: true,
285
- index: true,
286
- admin: { position: "sidebar" }
287
- };
288
264
  const baseFields = [
289
265
  {
290
266
  name: "title",
@@ -309,7 +285,7 @@ var createPostsCollection = (options = {}) => {
309
285
  type: "date",
310
286
  admin: { position: "sidebar" }
311
287
  },
312
- slugField
288
+ slugField()
313
289
  ];
314
290
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
315
291
  collectionSlug,
@@ -410,17 +386,18 @@ var createStaticPagesCollection = (blocks) => {
410
386
  };
411
387
 
412
388
  // src/core/fields/link.ts
413
- var appearanceOptions = {
389
+ var appearanceOptions2 = {
414
390
  default: { label: "Default", value: "default" },
415
391
  outline: { label: "Outline", value: "outline" }
416
392
  };
417
- var link = (options = {}) => {
393
+ var link2 = (options = {}) => {
418
394
  const {
419
395
  appearances,
420
396
  disableLabel = false,
421
397
  relationTo = [PAGES_SLUG],
422
398
  localized = false,
423
- overrides = {}
399
+ overrides = {},
400
+ extraFields = []
424
401
  } = options;
425
402
  const result = {
426
403
  name: "link",
@@ -488,7 +465,7 @@ var link = (options = {}) => {
488
465
  result.fields = [...result.fields, ...linkTypes];
489
466
  }
490
467
  if (appearances !== false) {
491
- const opts = appearances ? appearances.map((a) => appearanceOptions[a]) : [appearanceOptions.default, appearanceOptions.outline];
468
+ const opts = appearances ? appearances.map((a) => appearanceOptions2[a]) : [appearanceOptions2.default, appearanceOptions2.outline];
492
469
  result.fields.push({
493
470
  name: "appearance",
494
471
  type: "select",
@@ -497,6 +474,9 @@ var link = (options = {}) => {
497
474
  options: opts
498
475
  });
499
476
  }
477
+ if (extraFields.length) {
478
+ result.fields.push(...extraFields);
479
+ }
500
480
  return { ...result, ...overrides };
501
481
  };
502
482
 
@@ -516,17 +496,22 @@ function createRevalidateGlobalHook(slug) {
516
496
 
517
497
  // src/data/collections/globals/Header/config.ts
518
498
  var createHeaderGlobal = (options = {}) => {
519
- const { renderPath = HEADER_RENDER_PATH, linkRelationTo = [PAGES_SLUG] } = options;
499
+ const {
500
+ renderPath = HEADER_RENDER_PATH,
501
+ linkRelationTo = [PAGES_SLUG],
502
+ navColumnLinkFields = [],
503
+ navItemLinkFields = []
504
+ } = options;
520
505
  const navColumnBlock = {
521
506
  slug: "navColumn",
522
507
  fields: [
523
508
  { name: "title", type: "text", required: true, localized: true },
524
- { name: "links", type: "array", fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo })] }
509
+ { name: "links", type: "array", fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
525
510
  ]
526
511
  };
527
512
  const navItemBlock = {
528
513
  slug: "navItem",
529
- fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo })]
514
+ fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
530
515
  };
531
516
  return {
532
517
  slug: "header",
@@ -548,17 +533,22 @@ var createHeaderGlobal = (options = {}) => {
548
533
 
549
534
  // src/data/collections/globals/Footer/config.ts
550
535
  var createFooterGlobal = (options = {}) => {
551
- const { renderPath = FOOTER_RENDER_PATH, linkRelationTo = [PAGES_SLUG] } = options;
536
+ const {
537
+ renderPath = FOOTER_RENDER_PATH,
538
+ linkRelationTo = [PAGES_SLUG],
539
+ navColumnLinkFields = [],
540
+ navItemLinkFields = []
541
+ } = options;
552
542
  const navColumnBlock = {
553
543
  slug: "navColumn",
554
544
  fields: [
555
545
  { name: "title", type: "text", required: true, localized: true },
556
- { name: "links", type: "array", fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo })] }
546
+ { name: "links", type: "array", fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
557
547
  ]
558
548
  };
559
549
  const navItemBlock = {
560
550
  slug: "navItem",
561
- fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo })]
551
+ fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
562
552
  };
563
553
  return {
564
554
  slug: "footer",
package/dist/config.d.ts CHANGED
@@ -58,6 +58,14 @@ type WWWConfigOptions = {
58
58
  */
59
59
  registerPosts?: boolean;
60
60
  /**
61
+ * Enable nested (hierarchical) Pages slugs. When `true`, the lib's
62
+ * Pages collection accepts the `_` nesting divider in its slug
63
+ * (`about_us` → `/about/us`). Pass the same `nested: true` to
64
+ * `createCollectionPageExports` on the Pages route so URL building,
65
+ * hreflang, and static params expand the divider. Default: `false`.
66
+ */
67
+ nested?: boolean;
68
+ /**
61
69
  * Final say on the lib's default plugin list. Receives the
62
70
  * `[seoPlugin, imageHashPlugin, translator]` array; return the
63
71
  * list to apply. Common uses: drop the translator (no AI
package/dist/config.js CHANGED
@@ -23,7 +23,6 @@ var authenticatedOrPublished = ({ req: { user } }) => {
23
23
  return true;
24
24
  return { _status: { equals: "published" } };
25
25
  };
26
-
27
26
  // src/render/_locale.ts
28
27
  function prefixFor(locale, defaultLocale, mode) {
29
28
  if (mode === "never")
@@ -195,24 +194,9 @@ var createPagesCollection = (blocks, options = {}) => {
195
194
  renderPath = PAGES_RENDER_PATH,
196
195
  slug: collectionSlug = PAGES_SLUG2,
197
196
  localePrefix,
198
- defaultLocale
197
+ defaultLocale,
198
+ nested = false
199
199
  } = options;
200
- const slugField = {
201
- name: "slug",
202
- type: "text",
203
- required: true,
204
- unique: true,
205
- index: true,
206
- admin: { position: "sidebar" },
207
- validate: (value) => {
208
- if (typeof value !== "string")
209
- return "Slug must be a string";
210
- if (value !== "" && !/^[a-z0-9-]+$/.test(value)) {
211
- return "Slug must be lowercase, with hyphens (no spaces or special characters)";
212
- }
213
- return true;
214
- }
215
- };
216
200
  const baseFields = [
217
201
  {
218
202
  name: "title",
@@ -242,7 +226,7 @@ var createPagesCollection = (blocks, options = {}) => {
242
226
  type: "date",
243
227
  admin: { position: "sidebar" }
244
228
  },
245
- slugField
229
+ slugField({ nested })
246
230
  ];
247
231
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
248
232
  collectionSlug,
@@ -277,14 +261,6 @@ var createPostsCollection = (options = {}) => {
277
261
  localePrefix,
278
262
  defaultLocale
279
263
  } = options;
280
- const slugField = {
281
- name: "slug",
282
- type: "text",
283
- required: true,
284
- unique: true,
285
- index: true,
286
- admin: { position: "sidebar" }
287
- };
288
264
  const baseFields = [
289
265
  {
290
266
  name: "title",
@@ -309,7 +285,7 @@ var createPostsCollection = (options = {}) => {
309
285
  type: "date",
310
286
  admin: { position: "sidebar" }
311
287
  },
312
- slugField
288
+ slugField()
313
289
  ];
314
290
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
315
291
  collectionSlug,
@@ -410,17 +386,18 @@ var createStaticPagesCollection = (blocks) => {
410
386
  };
411
387
 
412
388
  // src/core/fields/link.ts
413
- var appearanceOptions = {
389
+ var appearanceOptions2 = {
414
390
  default: { label: "Default", value: "default" },
415
391
  outline: { label: "Outline", value: "outline" }
416
392
  };
417
- var link = (options = {}) => {
393
+ var link2 = (options = {}) => {
418
394
  const {
419
395
  appearances,
420
396
  disableLabel = false,
421
397
  relationTo = [PAGES_SLUG],
422
398
  localized = false,
423
- overrides = {}
399
+ overrides = {},
400
+ extraFields = []
424
401
  } = options;
425
402
  const result = {
426
403
  name: "link",
@@ -488,7 +465,7 @@ var link = (options = {}) => {
488
465
  result.fields = [...result.fields, ...linkTypes];
489
466
  }
490
467
  if (appearances !== false) {
491
- const opts = appearances ? appearances.map((a) => appearanceOptions[a]) : [appearanceOptions.default, appearanceOptions.outline];
468
+ const opts = appearances ? appearances.map((a) => appearanceOptions2[a]) : [appearanceOptions2.default, appearanceOptions2.outline];
492
469
  result.fields.push({
493
470
  name: "appearance",
494
471
  type: "select",
@@ -497,6 +474,9 @@ var link = (options = {}) => {
497
474
  options: opts
498
475
  });
499
476
  }
477
+ if (extraFields.length) {
478
+ result.fields.push(...extraFields);
479
+ }
500
480
  return { ...result, ...overrides };
501
481
  };
502
482
 
@@ -516,17 +496,22 @@ function createRevalidateGlobalHook(slug) {
516
496
 
517
497
  // src/data/collections/globals/Header/config.ts
518
498
  var createHeaderGlobal = (options = {}) => {
519
- const { renderPath = HEADER_RENDER_PATH, linkRelationTo = [PAGES_SLUG] } = options;
499
+ const {
500
+ renderPath = HEADER_RENDER_PATH,
501
+ linkRelationTo = [PAGES_SLUG],
502
+ navColumnLinkFields = [],
503
+ navItemLinkFields = []
504
+ } = options;
520
505
  const navColumnBlock = {
521
506
  slug: "navColumn",
522
507
  fields: [
523
508
  { name: "title", type: "text", required: true, localized: true },
524
- { name: "links", type: "array", fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo })] }
509
+ { name: "links", type: "array", fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
525
510
  ]
526
511
  };
527
512
  const navItemBlock = {
528
513
  slug: "navItem",
529
- fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo })]
514
+ fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
530
515
  };
531
516
  return {
532
517
  slug: "header",
@@ -548,17 +533,22 @@ var createHeaderGlobal = (options = {}) => {
548
533
 
549
534
  // src/data/collections/globals/Footer/config.ts
550
535
  var createFooterGlobal = (options = {}) => {
551
- const { renderPath = FOOTER_RENDER_PATH, linkRelationTo = [PAGES_SLUG] } = options;
536
+ const {
537
+ renderPath = FOOTER_RENDER_PATH,
538
+ linkRelationTo = [PAGES_SLUG],
539
+ navColumnLinkFields = [],
540
+ navItemLinkFields = []
541
+ } = options;
552
542
  const navColumnBlock = {
553
543
  slug: "navColumn",
554
544
  fields: [
555
545
  { name: "title", type: "text", required: true, localized: true },
556
- { name: "links", type: "array", fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo })] }
546
+ { name: "links", type: "array", fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
557
547
  ]
558
548
  };
559
549
  const navItemBlock = {
560
550
  slug: "navItem",
561
- fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo })]
551
+ fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
562
552
  };
563
553
  return {
564
554
  slug: "footer",
@@ -647,7 +637,7 @@ function getFromImportMap(key, importMap) {
647
637
  var queryDocBySlug = cache(async function queryDocBySlug2({
648
638
  collectionSlug,
649
639
  slug,
650
- slugField = "slug",
640
+ slugField: slugField2 = "slug",
651
641
  locale,
652
642
  draft = false,
653
643
  config
@@ -659,14 +649,14 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
659
649
  limit: 1,
660
650
  pagination: false,
661
651
  overrideAccess: draft,
662
- where: { [slugField]: { equals: slug } },
652
+ where: { [slugField2]: { equals: slug } },
663
653
  locale
664
654
  });
665
655
  return result.docs?.[0] ?? null;
666
656
  });
667
657
  var queryAllDocs = cache(async function queryAllDocs2({
668
658
  collectionSlug,
669
- slugField = "slug",
659
+ slugField: slugField2 = "slug",
670
660
  locale,
671
661
  config
672
662
  }) {
@@ -677,7 +667,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
677
667
  limit: 1000,
678
668
  pagination: false,
679
669
  overrideAccess: false,
680
- select: { [slugField]: true },
670
+ select: { [slugField2]: true },
681
671
  locale
682
672
  });
683
673
  return result.docs ?? [];
@@ -685,7 +675,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
685
675
  var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
686
676
  collectionSlug,
687
677
  slug,
688
- slugField = "slug",
678
+ slugField: slugField2 = "slug",
689
679
  locale,
690
680
  config
691
681
  }) {
@@ -697,13 +687,25 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
697
687
  pagination: false,
698
688
  overrideAccess: false,
699
689
  locale,
700
- where: { [slugField]: { equals: slug } },
701
- select: { [slugField]: true }
690
+ where: { [slugField2]: { equals: slug } },
691
+ select: { [slugField2]: true }
702
692
  });
703
693
  const doc = result.docs?.[0];
704
694
  if (!doc)
705
695
  return;
706
- const fieldValue = doc?.[slugField];
696
+ let fieldValue = doc[slugField2];
697
+ if (doc.id != null) {
698
+ const allLocales2 = await payload.findByID({
699
+ collection: collectionSlug,
700
+ id: doc.id,
701
+ locale: "all",
702
+ draft: false,
703
+ overrideAccess: false,
704
+ select: { [slugField2]: true }
705
+ }).catch(() => null);
706
+ if (allLocales2)
707
+ fieldValue = allLocales2[slugField2];
708
+ }
707
709
  if (fieldValue && typeof fieldValue === "object") {
708
710
  return fieldValue;
709
711
  }
@@ -756,6 +758,7 @@ function createSitemapFile(options) {
756
758
  const collectionDefaults = options.perCollection?.[collectionSlug] ?? {};
757
759
  const urlPrefix = (options.urlPrefixes?.[collectionSlug] ?? "").replace(/\/$/, "");
758
760
  const siteUrl = options.getServerSideURL().replace(/\/$/, "");
761
+ const isNested = options.nested?.[collectionSlug] ?? false;
759
762
  for (const locale of activeLocales) {
760
763
  const docs = await queryAllDocs({
761
764
  collectionSlug,
@@ -771,13 +774,14 @@ function createSitemapFile(options) {
771
774
  if (seen.has(dedupeKey))
772
775
  continue;
773
776
  seen.add(dedupeKey);
774
- const url = `${siteUrl}${prefixFor(locale, defaultLocale, options.localePrefix ?? "always")}${urlPrefix}/${storedSlug}`;
777
+ const slugPath = isNested ? storedSlug.replaceAll("_", "/") : storedSlug;
778
+ const url = `${siteUrl}${prefixFor(locale, defaultLocale, options.localePrefix ?? "always")}${urlPrefix}/${slugPath}`;
775
779
  const languages = await buildHreflangAlternates({
776
780
  siteUrl,
777
781
  locale,
778
782
  urlPrefix,
779
783
  storedSlug,
780
- nested: false,
784
+ nested: isNested,
781
785
  homeSlug: "",
782
786
  defaultLocale,
783
787
  locales: activeLocales,
@@ -808,7 +812,7 @@ function createSitemapFile(options) {
808
812
  }
809
813
  // src/config/createWWWConfig.ts
810
814
  function createWWWConfig(options) {
811
- const { locales, routing, blocks, linkRelationTo, registerPosts = true, defaultPlugins } = options;
815
+ const { locales, routing, blocks, linkRelationTo, registerPosts = true, nested = false, defaultPlugins } = options;
812
816
  const defaultLocale = routing?.defaultLocale ?? locales[0] ?? "";
813
817
  const localePrefixMode = (() => {
814
818
  const raw = routing?.localePrefix;
@@ -821,7 +825,8 @@ function createWWWConfig(options) {
821
825
  }
822
826
  const buildPagesCollection = () => createPagesCollection(blocks, {
823
827
  localePrefix: localePrefixMode,
824
- defaultLocale
828
+ defaultLocale,
829
+ nested
825
830
  });
826
831
  const buildPostsCollection = () => createPostsCollection({
827
832
  localePrefix: localePrefixMode,
@@ -20,10 +20,46 @@ type LinkOptions = {
20
20
  overrides?: Partial<GroupField>;
21
21
  /** Legacy alias for the host's custom field overrides. */
22
22
  linkOverrides?: Partial<GroupField>;
23
+ /**
24
+ * Extra fields appended to the link group — e.g. a `description`
25
+ * text field or a `navHover` group for a mega-menu. Lets hosts
26
+ * extend the nav link schema without re-implementing the whole
27
+ * `link` field. Appended after the standard type/label/appearance
28
+ * fields.
29
+ */
30
+ extraFields?: Field[];
23
31
  };
24
32
  declare const link: (options?: LinkOptions) => Field;
25
33
  import { Field as Field2 } from "payload";
26
34
  declare const linkGroup: (options?: LinkOptions) => Field2;
35
+ import { Field as Field3 } from "payload";
36
+ type SlugFieldOptions = {
37
+ /** Field name. Default: `'slug'`. */
38
+ name?: string;
39
+ /**
40
+ * Allow the `_` nesting divider in the slug so `about_us` renders at
41
+ * `/about/us`. Relaxes validation and documents the convention in the
42
+ * admin UI. Pair with `createCollectionPageExports({ nested: true })`.
43
+ * Default: `false`.
44
+ */
45
+ nested?: boolean;
46
+ /**
47
+ * Localize the slug — one slug per locale (`/about` in `en`, `/o-nas`
48
+ * in `sk`), stored in the collection's `_locales` table. This is the
49
+ * default: the lib's collections are multilingual, so per-locale slugs
50
+ * power localized URLs and hreflang alternates. Pass `false` for a
51
+ * single shared slug.
52
+ */
53
+ localized?: boolean;
54
+ };
55
+ /**
56
+ * The slug field shared by the lib's Pages / Posts collections: a
57
+ * required, unique, indexed, sidebar text field, localized by default.
58
+ *
59
+ * The empty string is reserved for the home page (rendered at
60
+ * `/${locale}`), so validation only rejects non-empty malformed values.
61
+ */
62
+ declare const slugField: (options?: SlugFieldOptions) => Field3;
27
63
  import { Field as Field_14espm } from "payload";
28
64
  declare const _default: {
29
65
  link: (options?: LinkOptions) => Field_14espm;
@@ -32,5 +68,6 @@ declare const _default: {
32
68
  label: string;
33
69
  value: string;
34
70
  }>;
71
+ slugField: (options?: SlugFieldOptions) => Field_14espm;
35
72
  };
36
- export { linkGroup, link, _default as default, appearanceOptions, LinkOptions, LinkAppearances };
73
+ export { slugField, linkGroup, link, _default as default, appearanceOptions, SlugFieldOptions, LinkOptions, LinkAppearances };
@@ -36,7 +36,8 @@ var link = (options = {}) => {
36
36
  disableLabel = false,
37
37
  relationTo = [PAGES_SLUG],
38
38
  localized = false,
39
- overrides = {}
39
+ overrides = {},
40
+ extraFields = []
40
41
  } = options;
41
42
  const result = {
42
43
  name: "link",
@@ -113,6 +114,9 @@ var link = (options = {}) => {
113
114
  options: opts
114
115
  });
115
116
  }
117
+ if (extraFields.length) {
118
+ result.fields.push(...extraFields);
119
+ }
116
120
  return { ...result, ...overrides };
117
121
  };
118
122
 
@@ -124,9 +128,38 @@ var linkGroup = (options = {}) => ({
124
128
  admin: { initCollapsed: true }
125
129
  });
126
130
 
131
+ // src/core/fields/slug.ts
132
+ var FLAT_PATTERN = /^[a-z0-9-]+$/;
133
+ var NESTED_PATTERN = /^[a-z0-9_-]+$/;
134
+ var slugField = (options = {}) => {
135
+ const { name = "slug", nested = false, localized = true } = options;
136
+ const pattern = nested ? NESTED_PATTERN : FLAT_PATTERN;
137
+ const invalidMessage = nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
138
+ return {
139
+ name,
140
+ type: "text",
141
+ required: true,
142
+ unique: true,
143
+ index: true,
144
+ localized,
145
+ admin: {
146
+ position: "sidebar",
147
+ ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
148
+ },
149
+ validate: (value) => {
150
+ if (typeof value !== "string")
151
+ return "Slug must be a string";
152
+ if (value !== "" && !pattern.test(value))
153
+ return invalidMessage;
154
+ return true;
155
+ }
156
+ };
157
+ };
158
+
127
159
  // src/exports/core-fields.ts
128
- var core_fields_default = { link, linkGroup, appearanceOptions };
160
+ var core_fields_default = { link, linkGroup, appearanceOptions, slugField };
129
161
  export {
162
+ slugField,
130
163
  linkGroup,
131
164
  link,
132
165
  core_fields_default as default,