@justanarthur/payload-www 2.2.7 → 2.2.9

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
@@ -144,6 +144,7 @@ const { default: PostPage, generateMetadata, generateStaticParams } = createColl
144
144
  | `routing` | `RoutingConfig` | required | `{ locales, defaultLocale, localePrefix, labels? }` from `next-intl/routing`'s `defineRouting` |
145
145
  | `slug` | `string` | `'pages'` | collection slug to query |
146
146
  | `slugShape` | `'single' \| 'catch-all'` | `'single'` | drives `generateStaticParams` + slug segmentation |
147
+ | `depth` | `number` | `2` | relationship / upload hops populated on the rendered document. `0` hands every media and relationship field to the render component as a bare id. Enumeration (`generateStaticParams`, `generateSitemap`) stays at `0` regardless. |
147
148
 
148
149
  ### `createCollectionPageExports(args, deps)` — deps
149
150
 
@@ -171,6 +172,7 @@ const { default: PostPage, generateMetadata, generateStaticParams } = createColl
171
172
  | `config` | `Promise<SanitizedConfig>` | required |
172
173
  | `importMap` | `ImportMap` | required |
173
174
  | `routing` | `RoutingConfig` | required |
175
+ | `depth` | `number` | relationship / upload hops populated on the `header` + `footer` globals. Defaults to `2`. |
174
176
 
175
177
  | dep | type | notes |
176
178
  |---|---|---|
@@ -20,6 +20,7 @@ type QueryDocArgs = ({
20
20
  globalSlug: string;
21
21
  locale: string;
22
22
  draft?: boolean;
23
+ depth?: number;
23
24
  }) | ({
24
25
  collectionSlug: string;
25
26
  slug: string;
@@ -86,6 +86,32 @@ import { createCacheHelpers } from "@pro-laico/payload-revalidate/cache";
86
86
  import { tagsFor } from "@pro-laico/payload-revalidate";
87
87
  import { cacheLife } from "next/cache";
88
88
  import { getPayload } from "payload";
89
+
90
+ // src/render/metadata/slug.ts
91
+ var SLUG_NESTED_DIVIDER = "_";
92
+ function paramsSlugToSlug(slug, _shape) {
93
+ if (!slug)
94
+ return "";
95
+ return (Array.isArray(slug) ? slug : [slug]).join(SLUG_NESTED_DIVIDER);
96
+ }
97
+ function slugToParamsSlug(slug, shape) {
98
+ if (!slug)
99
+ return shape === "catch-all" ? [] : "";
100
+ return shape === "catch-all" ? slug.split(SLUG_NESTED_DIVIDER) : slug;
101
+ }
102
+ function isIndexSlug(slug) {
103
+ return !slug;
104
+ }
105
+ function shapeHasIndexPath(shape) {
106
+ return shape === "catch-all";
107
+ }
108
+ function slugToPath(slug) {
109
+ if (!slug)
110
+ return "";
111
+ return slug.split(SLUG_NESTED_DIVIDER).join("/");
112
+ }
113
+
114
+ // src/render/metadata/query.ts
89
115
  var _helpers = null;
90
116
  var _seedPromise = null;
91
117
  function seedPayloadCache({ config }) {
@@ -106,19 +132,22 @@ async function requireCacheHelpers() {
106
132
  }
107
133
  throw new Error("[payload-www] seedPayloadCache({ config }) must be called before any query getter. " + "Call it from createCollectionPageExports / createRootLayoutExports factory, or in your root layout.");
108
134
  }
135
+ var RENDER_DEPTH = 2;
109
136
  async function queryDocBySlug(args) {
110
137
  "use cache";
111
138
  cacheLife("weeks");
112
139
  const { findDoc } = await requireCacheHelpers();
113
140
  const slugField = args.slugField ?? "slug";
114
- const result = await findDoc(args.collectionSlug, {
115
- where: { [slugField]: { equals: args.slug } },
141
+ const find = (slug) => findDoc(args.collectionSlug, {
142
+ where: { [slugField]: { equals: slug } },
116
143
  locale: args.locale,
117
144
  draft: args.draft ?? false,
118
145
  overrideAccess: args.draft ?? false,
119
- depth: args.depth
146
+ depth: args.depth ?? RENDER_DEPTH
120
147
  });
121
- return result ?? null;
148
+ const result = await find(args.slug);
149
+ const doc = result ?? (isIndexSlug(args.slug) ? await find(null) : null);
150
+ return doc ?? null;
122
151
  }
123
152
  async function queryGlobal(args) {
124
153
  "use cache";
@@ -128,7 +157,7 @@ async function queryGlobal(args) {
128
157
  const result = await findGlobal(args.globalSlug, {
129
158
  locale: args.locale,
130
159
  draft: args.draft ?? false,
131
- depth: args.depth
160
+ depth: args.depth ?? RENDER_DEPTH
132
161
  });
133
162
  return result ?? null;
134
163
  } catch (error) {
@@ -144,7 +173,7 @@ async function queryAllDocs(args) {
144
173
  const { ids } = await findIds(collection, { locale: args.locale, pagination: false, overrideAccess: false });
145
174
  if (ids.length === 0)
146
175
  return [];
147
- const docs = await Promise.all(ids.map((id) => findDocByID(collection, id, { locale: args.locale, overrideAccess: false })));
176
+ const docs = await Promise.all(ids.map((id) => findDocByID(collection, id, { locale: args.locale, overrideAccess: false, depth: 0 })));
148
177
  return docs.filter((d) => d !== null);
149
178
  }
150
179
  async function queryDoc(args) {
@@ -171,7 +200,7 @@ async function queryDocByID(args) {
171
200
  locale: args.locale,
172
201
  draft: args.draft ?? false,
173
202
  overrideAccess: args.draft ?? false,
174
- depth: args.depth
203
+ depth: args.depth ?? RENDER_DEPTH
175
204
  });
176
205
  }
177
206
 
@@ -20,6 +20,8 @@ import { BuildOrganizationLdOptions, BuildProductLdOptions, BuildRootJsonLdOptio
20
20
  type SlugShape = "single" | "catch-all";
21
21
  declare function paramsSlugToSlug(slug: string | string[] | undefined, _shape: SlugShape): string;
22
22
  declare function slugToParamsSlug(slug: string, shape: SlugShape): string | string[];
23
+ declare function isIndexSlug(slug: string | null | undefined): boolean;
24
+ declare function shapeHasIndexPath(shape: SlugShape): boolean;
23
25
  import { DataFromCollectionSlug, DataFromGlobalSlug, SanitizedConfig } from "payload";
24
26
  import { tagsFor } from "@pro-laico/payload-revalidate";
25
27
  type SeedPayloadCacheArgs = {
@@ -76,7 +78,9 @@ declare const metadata: {
76
78
  queryAllLocaleSlugs: typeof queryAllLocaleSlugs;
77
79
  paramsSlugToSlug: typeof paramsSlugToSlug;
78
80
  slugToParamsSlug: typeof slugToParamsSlug;
81
+ isIndexSlug: typeof isIndexSlug;
82
+ shapeHasIndexPath: typeof shapeHasIndexPath;
79
83
  seedPayloadCache: typeof seedPayloadCache;
80
84
  tagsFor: (payload: Payload_eipjla) => Tags_1jpdl;
81
85
  };
82
- export { ArticleLdOptions, BreadcrumbItem, BuildOrganizationLdOptions, BuildProductLdOptions, BuildRootJsonLdOptions, BuildWebSiteLdOptions, SeedPayloadCacheArgs, SlugShape, buildArticleLd, buildBreadcrumbsLd, buildOrganizationLd, buildProductLd, buildRootJsonLd, buildWebSiteLd, metadata as default, paramsSlugToSlug, queryAllDocs, queryAllLocaleSlugs, queryDocByID, queryDocBySlug, queryGlobal, seedPayloadCache, slugToParamsSlug, tagsFor };
86
+ export { ArticleLdOptions, BreadcrumbItem, BuildOrganizationLdOptions, BuildProductLdOptions, BuildRootJsonLdOptions, BuildWebSiteLdOptions, SeedPayloadCacheArgs, SlugShape, buildArticleLd, buildBreadcrumbsLd, buildOrganizationLd, buildProductLd, buildRootJsonLd, buildWebSiteLd, metadata as default, isIndexSlug, paramsSlugToSlug, queryAllDocs, queryAllLocaleSlugs, queryDocByID, queryDocBySlug, queryGlobal, seedPayloadCache, shapeHasIndexPath, slugToParamsSlug, tagsFor };
package/dist/metadata.js CHANGED
@@ -103,6 +103,12 @@ function slugToParamsSlug(slug, shape) {
103
103
  return shape === "catch-all" ? [] : "";
104
104
  return shape === "catch-all" ? slug.split(SLUG_NESTED_DIVIDER) : slug;
105
105
  }
106
+ function isIndexSlug(slug) {
107
+ return !slug;
108
+ }
109
+ function shapeHasIndexPath(shape) {
110
+ return shape === "catch-all";
111
+ }
106
112
  function slugToPath(slug) {
107
113
  if (!slug)
108
114
  return "";
@@ -134,19 +140,22 @@ async function requireCacheHelpers() {
134
140
  }
135
141
  throw new Error("[payload-www] seedPayloadCache({ config }) must be called before any query getter. " + "Call it from createCollectionPageExports / createRootLayoutExports factory, or in your root layout.");
136
142
  }
143
+ var RENDER_DEPTH = 2;
137
144
  async function queryDocBySlug(args) {
138
145
  "use cache";
139
146
  cacheLife("weeks");
140
147
  const { findDoc } = await requireCacheHelpers();
141
148
  const slugField = args.slugField ?? "slug";
142
- const result = await findDoc(args.collectionSlug, {
143
- where: { [slugField]: { equals: args.slug } },
149
+ const find = (slug) => findDoc(args.collectionSlug, {
150
+ where: { [slugField]: { equals: slug } },
144
151
  locale: args.locale,
145
152
  draft: args.draft ?? false,
146
153
  overrideAccess: args.draft ?? false,
147
- depth: args.depth
154
+ depth: args.depth ?? RENDER_DEPTH
148
155
  });
149
- return result ?? null;
156
+ const result = await find(args.slug);
157
+ const doc = result ?? (isIndexSlug(args.slug) ? await find(null) : null);
158
+ return doc ?? null;
150
159
  }
151
160
  async function queryGlobal(args) {
152
161
  "use cache";
@@ -156,7 +165,7 @@ async function queryGlobal(args) {
156
165
  const result = await findGlobal(args.globalSlug, {
157
166
  locale: args.locale,
158
167
  draft: args.draft ?? false,
159
- depth: args.depth
168
+ depth: args.depth ?? RENDER_DEPTH
160
169
  });
161
170
  return result ?? null;
162
171
  } catch (error) {
@@ -172,7 +181,7 @@ async function queryAllDocs(args) {
172
181
  const { ids } = await findIds(collection, { locale: args.locale, pagination: false, overrideAccess: false });
173
182
  if (ids.length === 0)
174
183
  return [];
175
- const docs = await Promise.all(ids.map((id) => findDocByID(collection, id, { locale: args.locale, overrideAccess: false })));
184
+ const docs = await Promise.all(ids.map((id) => findDocByID(collection, id, { locale: args.locale, overrideAccess: false, depth: 0 })));
176
185
  return docs.filter((d) => d !== null);
177
186
  }
178
187
  async function queryDoc(args) {
@@ -199,7 +208,7 @@ async function queryDocByID(args) {
199
208
  locale: args.locale,
200
209
  draft: args.draft ?? false,
201
210
  overrideAccess: args.draft ?? false,
202
- depth: args.depth
211
+ depth: args.depth ?? RENDER_DEPTH
203
212
  });
204
213
  }
205
214
 
@@ -218,6 +227,8 @@ var metadata = {
218
227
  queryAllLocaleSlugs,
219
228
  paramsSlugToSlug,
220
229
  slugToParamsSlug,
230
+ isIndexSlug,
231
+ shapeHasIndexPath,
221
232
  seedPayloadCache,
222
233
  tagsFor
223
234
  };
@@ -230,6 +241,7 @@ export {
230
241
  buildRootJsonLd,
231
242
  buildWebSiteLd,
232
243
  metadata_default as default,
244
+ isIndexSlug,
233
245
  paramsSlugToSlug,
234
246
  queryAllDocs,
235
247
  queryAllLocaleSlugs,
@@ -237,6 +249,7 @@ export {
237
249
  queryDocBySlug,
238
250
  queryGlobal,
239
251
  seedPayloadCache,
252
+ shapeHasIndexPath,
240
253
  slugToParamsSlug,
241
254
  tagsFor
242
255
  };
package/dist/pages.d.ts CHANGED
@@ -39,6 +39,8 @@ type CreateCollectionPageExportsArgs<S extends string = "pages"> = {
39
39
  importMap: ImportMap3;
40
40
  routing: RoutingConfig;
41
41
  slugShape?: SlugShape;
42
+ /** Relationship / upload hops populated on the rendered document. `0` renders them as bare ids. */
43
+ depth?: number;
42
44
  };
43
45
  type CreateCollectionPageExportsDeps<S extends string> = {
44
46
  getServerSideURL: () => string;
@@ -46,7 +48,7 @@ type CreateCollectionPageExportsDeps<S extends string> = {
46
48
  /** Rendered while the document streams. Defaults to nothing. */
47
49
  fallback?: ReactNode2;
48
50
  };
49
- declare function createCollectionPageExports<S extends string = "pages">({ slug: collectionSlug, _payloadConfig, importMap, routing, slugShape }: CreateCollectionPageExportsArgs<S>, { getServerSideURL, pagePathPrefix, fallback }: CreateCollectionPageExportsDeps<S>): {
51
+ declare function createCollectionPageExports<S extends string = "pages">({ slug: collectionSlug, _payloadConfig, importMap, routing, slugShape, depth }: CreateCollectionPageExportsArgs<S>, { getServerSideURL, pagePathPrefix, fallback }: CreateCollectionPageExportsDeps<S>): {
50
52
  default: (props: NextPageProps) => Promise<ReactNode2>;
51
53
  generateMetadata: (props: NextPageProps) => Promise<Metadata>;
52
54
  generateStaticParams: (props: GenerateStaticParamsProps) => Promise<{
package/dist/pages.js CHANGED
@@ -188,6 +188,12 @@ function slugToParamsSlug(slug, shape) {
188
188
  return shape === "catch-all" ? [] : "";
189
189
  return shape === "catch-all" ? slug.split(SLUG_NESTED_DIVIDER) : slug;
190
190
  }
191
+ function isIndexSlug(slug) {
192
+ return !slug;
193
+ }
194
+ function shapeHasIndexPath(shape) {
195
+ return shape === "catch-all";
196
+ }
191
197
  function slugToPath(slug) {
192
198
  if (!slug)
193
199
  return "";
@@ -219,19 +225,22 @@ async function requireCacheHelpers() {
219
225
  }
220
226
  throw new Error("[payload-www] seedPayloadCache({ config }) must be called before any query getter. " + "Call it from createCollectionPageExports / createRootLayoutExports factory, or in your root layout.");
221
227
  }
228
+ var RENDER_DEPTH = 2;
222
229
  async function queryDocBySlug(args) {
223
230
  "use cache";
224
231
  cacheLife("weeks");
225
232
  const { findDoc } = await requireCacheHelpers();
226
233
  const slugField = args.slugField ?? "slug";
227
- const result = await findDoc(args.collectionSlug, {
228
- where: { [slugField]: { equals: args.slug } },
234
+ const find = (slug) => findDoc(args.collectionSlug, {
235
+ where: { [slugField]: { equals: slug } },
229
236
  locale: args.locale,
230
237
  draft: args.draft ?? false,
231
238
  overrideAccess: args.draft ?? false,
232
- depth: args.depth
239
+ depth: args.depth ?? RENDER_DEPTH
233
240
  });
234
- return result ?? null;
241
+ const result = await find(args.slug);
242
+ const doc = result ?? (isIndexSlug(args.slug) ? await find(null) : null);
243
+ return doc ?? null;
235
244
  }
236
245
  async function queryGlobal(args) {
237
246
  "use cache";
@@ -241,7 +250,7 @@ async function queryGlobal(args) {
241
250
  const result = await findGlobal(args.globalSlug, {
242
251
  locale: args.locale,
243
252
  draft: args.draft ?? false,
244
- depth: args.depth
253
+ depth: args.depth ?? RENDER_DEPTH
245
254
  });
246
255
  return result ?? null;
247
256
  } catch (error) {
@@ -257,7 +266,7 @@ async function queryAllDocs(args) {
257
266
  const { ids } = await findIds(collection, { locale: args.locale, pagination: false, overrideAccess: false });
258
267
  if (ids.length === 0)
259
268
  return [];
260
- const docs = await Promise.all(ids.map((id) => findDocByID(collection, id, { locale: args.locale, overrideAccess: false })));
269
+ const docs = await Promise.all(ids.map((id) => findDocByID(collection, id, { locale: args.locale, overrideAccess: false, depth: 0 })));
261
270
  return docs.filter((d) => d !== null);
262
271
  }
263
272
  async function queryDoc(args) {
@@ -284,7 +293,7 @@ async function queryDocByID(args) {
284
293
  locale: args.locale,
285
294
  draft: args.draft ?? false,
286
295
  overrideAccess: args.draft ?? false,
287
- depth: args.depth
296
+ depth: args.depth ?? RENDER_DEPTH
288
297
  });
289
298
  }
290
299
 
@@ -360,7 +369,8 @@ function createCollectionPageExports({
360
369
  _payloadConfig,
361
370
  importMap,
362
371
  routing,
363
- slugShape = "single"
372
+ slugShape = "single",
373
+ depth = RENDER_DEPTH
364
374
  }, {
365
375
  getServerSideURL,
366
376
  pagePathPrefix,
@@ -372,6 +382,7 @@ function createCollectionPageExports({
372
382
  return queryDoc({
373
383
  slug,
374
384
  locale,
385
+ depth,
375
386
  collectionSlug
376
387
  });
377
388
  }
@@ -428,7 +439,10 @@ function createCollectionPageExports({
428
439
  await props.params;
429
440
  const perLocaleEntries = await Promise.all(routing.locales.map(async (locale) => {
430
441
  const docs = await queryAllDocs({ locale, collectionSlug });
431
- return docs.filter((doc) => typeof doc.slug === "string" && doc.slug.length > 0).map((doc) => ({ locale, slug: slugToParamsSlug(doc.slug, slugShape) }));
442
+ const entries = docs.filter((doc) => !isIndexSlug(doc.slug)).map((doc) => ({ locale, slug: slugToParamsSlug(doc.slug, slugShape) }));
443
+ if (shapeHasIndexPath(slugShape) && await fetchDoc(locale, ""))
444
+ entries.push({ locale, slug: slugToParamsSlug("", slugShape) });
445
+ return entries;
432
446
  }));
433
447
  return perLocaleEntries.flat();
434
448
  }
@@ -48,6 +48,8 @@ type CreateCollectionPageExportsArgs<S extends string = "pages"> = {
48
48
  importMap: ImportMap3;
49
49
  routing: RoutingConfig;
50
50
  slugShape?: SlugShape;
51
+ /** Relationship / upload hops populated on the rendered document. `0` renders them as bare ids. */
52
+ depth?: number;
51
53
  };
52
54
  type CreateCollectionPageExportsDeps<S extends string> = {
53
55
  getServerSideURL: () => string;
@@ -55,7 +57,7 @@ type CreateCollectionPageExportsDeps<S extends string> = {
55
57
  /** Rendered while the document streams. Defaults to nothing. */
56
58
  fallback?: ReactNode2;
57
59
  };
58
- declare function createCollectionPageExports<S extends string = "pages">({ slug: collectionSlug, _payloadConfig, importMap, routing, slugShape }: CreateCollectionPageExportsArgs<S>, { getServerSideURL, pagePathPrefix, fallback }: CreateCollectionPageExportsDeps<S>): {
60
+ declare function createCollectionPageExports<S extends string = "pages">({ slug: collectionSlug, _payloadConfig, importMap, routing, slugShape, depth }: CreateCollectionPageExportsArgs<S>, { getServerSideURL, pagePathPrefix, fallback }: CreateCollectionPageExportsDeps<S>): {
59
61
  default: (props: NextPageProps) => Promise<ReactNode2>;
60
62
  generateMetadata: (props: NextPageProps) => Promise<Metadata>;
61
63
  generateStaticParams: (props: GenerateStaticParamsProps) => Promise<{
@@ -75,6 +77,8 @@ type CreateRootLayoutExportsArgs = {
75
77
  _payloadConfig: Promise<SanitizedConfig3>;
76
78
  importMap: ImportMap4;
77
79
  routing: RoutingConfig;
80
+ /** Relationship / upload hops populated on the header and footer globals. `0` renders them as bare ids. */
81
+ depth?: number;
78
82
  };
79
83
  type CreateRootLayoutProvidersArgs = {
80
84
  children: ReactNode3;
@@ -86,7 +90,7 @@ type CreateRootLayoutExportsDeps = {
86
90
  getServerSideURL?: () => string;
87
91
  };
88
92
  type Element_12xgc2 = JSX_1kxb2["Element"];
89
- declare function createRootLayoutExports({ _payloadConfig, importMap, routing }: CreateRootLayoutExportsArgs, { providers, htmlAttrs, getServerSideURL }?: CreateRootLayoutExportsDeps): {
93
+ declare function createRootLayoutExports({ _payloadConfig, importMap, routing, depth }: CreateRootLayoutExportsArgs, { providers, htmlAttrs, getServerSideURL }?: CreateRootLayoutExportsDeps): {
90
94
  default: (props: NextLayoutProps) => Promise<Element_12xgc2>;
91
95
  generateStaticParams: () => {
92
96
  locale: string;
@@ -218,6 +218,12 @@ function slugToParamsSlug(slug, shape) {
218
218
  return shape === "catch-all" ? [] : "";
219
219
  return shape === "catch-all" ? slug.split(SLUG_NESTED_DIVIDER) : slug;
220
220
  }
221
+ function isIndexSlug(slug) {
222
+ return !slug;
223
+ }
224
+ function shapeHasIndexPath(shape) {
225
+ return shape === "catch-all";
226
+ }
221
227
  function slugToPath(slug) {
222
228
  if (!slug)
223
229
  return "";
@@ -249,19 +255,22 @@ async function requireCacheHelpers() {
249
255
  }
250
256
  throw new Error("[payload-www] seedPayloadCache({ config }) must be called before any query getter. " + "Call it from createCollectionPageExports / createRootLayoutExports factory, or in your root layout.");
251
257
  }
258
+ var RENDER_DEPTH = 2;
252
259
  async function queryDocBySlug(args) {
253
260
  "use cache";
254
261
  cacheLife("weeks");
255
262
  const { findDoc } = await requireCacheHelpers();
256
263
  const slugField = args.slugField ?? "slug";
257
- const result = await findDoc(args.collectionSlug, {
258
- where: { [slugField]: { equals: args.slug } },
264
+ const find = (slug) => findDoc(args.collectionSlug, {
265
+ where: { [slugField]: { equals: slug } },
259
266
  locale: args.locale,
260
267
  draft: args.draft ?? false,
261
268
  overrideAccess: args.draft ?? false,
262
- depth: args.depth
269
+ depth: args.depth ?? RENDER_DEPTH
263
270
  });
264
- return result ?? null;
271
+ const result = await find(args.slug);
272
+ const doc = result ?? (isIndexSlug(args.slug) ? await find(null) : null);
273
+ return doc ?? null;
265
274
  }
266
275
  async function queryGlobal(args) {
267
276
  "use cache";
@@ -271,7 +280,7 @@ async function queryGlobal(args) {
271
280
  const result = await findGlobal(args.globalSlug, {
272
281
  locale: args.locale,
273
282
  draft: args.draft ?? false,
274
- depth: args.depth
283
+ depth: args.depth ?? RENDER_DEPTH
275
284
  });
276
285
  return result ?? null;
277
286
  } catch (error) {
@@ -287,7 +296,7 @@ async function queryAllDocs(args) {
287
296
  const { ids } = await findIds(collection, { locale: args.locale, pagination: false, overrideAccess: false });
288
297
  if (ids.length === 0)
289
298
  return [];
290
- const docs = await Promise.all(ids.map((id) => findDocByID(collection, id, { locale: args.locale, overrideAccess: false })));
299
+ const docs = await Promise.all(ids.map((id) => findDocByID(collection, id, { locale: args.locale, overrideAccess: false, depth: 0 })));
291
300
  return docs.filter((d) => d !== null);
292
301
  }
293
302
  async function queryDoc(args) {
@@ -314,7 +323,7 @@ async function queryDocByID(args) {
314
323
  locale: args.locale,
315
324
  draft: args.draft ?? false,
316
325
  overrideAccess: args.draft ?? false,
317
- depth: args.depth
326
+ depth: args.depth ?? RENDER_DEPTH
318
327
  });
319
328
  }
320
329
 
@@ -390,7 +399,8 @@ function createCollectionPageExports({
390
399
  _payloadConfig,
391
400
  importMap,
392
401
  routing,
393
- slugShape = "single"
402
+ slugShape = "single",
403
+ depth = RENDER_DEPTH
394
404
  }, {
395
405
  getServerSideURL,
396
406
  pagePathPrefix,
@@ -402,6 +412,7 @@ function createCollectionPageExports({
402
412
  return queryDoc({
403
413
  slug,
404
414
  locale,
415
+ depth,
405
416
  collectionSlug
406
417
  });
407
418
  }
@@ -458,7 +469,10 @@ function createCollectionPageExports({
458
469
  await props.params;
459
470
  const perLocaleEntries = await Promise.all(routing.locales.map(async (locale) => {
460
471
  const docs = await queryAllDocs({ locale, collectionSlug });
461
- return docs.filter((doc) => typeof doc.slug === "string" && doc.slug.length > 0).map((doc) => ({ locale, slug: slugToParamsSlug(doc.slug, slugShape) }));
472
+ const entries = docs.filter((doc) => !isIndexSlug(doc.slug)).map((doc) => ({ locale, slug: slugToParamsSlug(doc.slug, slugShape) }));
473
+ if (shapeHasIndexPath(slugShape) && await fetchDoc(locale, ""))
474
+ entries.push({ locale, slug: slugToParamsSlug("", slugShape) });
475
+ return entries;
462
476
  }));
463
477
  return perLocaleEntries.flat();
464
478
  }
@@ -524,7 +538,8 @@ async function resolveLocale(props) {
524
538
  function createRootLayoutExports({
525
539
  _payloadConfig,
526
540
  importMap,
527
- routing
541
+ routing,
542
+ depth = RENDER_DEPTH
528
543
  }, {
529
544
  providers,
530
545
  htmlAttrs,
@@ -542,8 +557,8 @@ function createRootLayoutExports({
542
557
  header,
543
558
  footer
544
559
  ] = await Promise.all([
545
- queryDoc({ globalSlug: "header", locale }),
546
- queryDoc({ globalSlug: "footer", locale })
560
+ queryDoc({ globalSlug: "header", locale, depth }),
561
+ queryDoc({ globalSlug: "footer", locale, depth })
547
562
  ]);
548
563
  const renderedHeader = renderWWWDataModule(header, { collectionSlug: "header", configPath: "globals", config: _payloadConfig, importMap }, { ...props, locale }), renderedFooter = renderWWWDataModule(footer, { collectionSlug: "footer", configPath: "globals", config: _payloadConfig, importMap }, { ...props, locale });
549
564
  const mergedHtmlAttrs = {
package/dist/sitemap.js CHANGED
@@ -13,6 +13,12 @@ function slugToParamsSlug(slug, shape) {
13
13
  return shape === "catch-all" ? [] : "";
14
14
  return shape === "catch-all" ? slug.split(SLUG_NESTED_DIVIDER) : slug;
15
15
  }
16
+ function isIndexSlug(slug) {
17
+ return !slug;
18
+ }
19
+ function shapeHasIndexPath(shape) {
20
+ return shape === "catch-all";
21
+ }
16
22
  function slugToPath(slug) {
17
23
  if (!slug)
18
24
  return "";
@@ -44,19 +50,22 @@ async function requireCacheHelpers() {
44
50
  }
45
51
  throw new Error("[payload-www] seedPayloadCache({ config }) must be called before any query getter. " + "Call it from createCollectionPageExports / createRootLayoutExports factory, or in your root layout.");
46
52
  }
53
+ var RENDER_DEPTH = 2;
47
54
  async function queryDocBySlug(args) {
48
55
  "use cache";
49
56
  cacheLife("weeks");
50
57
  const { findDoc } = await requireCacheHelpers();
51
58
  const slugField = args.slugField ?? "slug";
52
- const result = await findDoc(args.collectionSlug, {
53
- where: { [slugField]: { equals: args.slug } },
59
+ const find = (slug) => findDoc(args.collectionSlug, {
60
+ where: { [slugField]: { equals: slug } },
54
61
  locale: args.locale,
55
62
  draft: args.draft ?? false,
56
63
  overrideAccess: args.draft ?? false,
57
- depth: args.depth
64
+ depth: args.depth ?? RENDER_DEPTH
58
65
  });
59
- return result ?? null;
66
+ const result = await find(args.slug);
67
+ const doc = result ?? (isIndexSlug(args.slug) ? await find(null) : null);
68
+ return doc ?? null;
60
69
  }
61
70
  async function queryGlobal(args) {
62
71
  "use cache";
@@ -66,7 +75,7 @@ async function queryGlobal(args) {
66
75
  const result = await findGlobal(args.globalSlug, {
67
76
  locale: args.locale,
68
77
  draft: args.draft ?? false,
69
- depth: args.depth
78
+ depth: args.depth ?? RENDER_DEPTH
70
79
  });
71
80
  return result ?? null;
72
81
  } catch (error) {
@@ -82,7 +91,7 @@ async function queryAllDocs(args) {
82
91
  const { ids } = await findIds(collection, { locale: args.locale, pagination: false, overrideAccess: false });
83
92
  if (ids.length === 0)
84
93
  return [];
85
- const docs = await Promise.all(ids.map((id) => findDocByID(collection, id, { locale: args.locale, overrideAccess: false })));
94
+ const docs = await Promise.all(ids.map((id) => findDocByID(collection, id, { locale: args.locale, overrideAccess: false, depth: 0 })));
86
95
  return docs.filter((d) => d !== null);
87
96
  }
88
97
  async function queryDoc(args) {
@@ -109,7 +118,7 @@ async function queryDocByID(args) {
109
118
  locale: args.locale,
110
119
  draft: args.draft ?? false,
111
120
  overrideAccess: args.draft ?? false,
112
- depth: args.depth
121
+ depth: args.depth ?? RENDER_DEPTH
113
122
  });
114
123
  }
115
124
 
@@ -206,7 +215,8 @@ function createCollectionPageExports({
206
215
  _payloadConfig,
207
216
  importMap,
208
217
  routing,
209
- slugShape = "single"
218
+ slugShape = "single",
219
+ depth = RENDER_DEPTH
210
220
  }, {
211
221
  getServerSideURL,
212
222
  pagePathPrefix,
@@ -218,6 +228,7 @@ function createCollectionPageExports({
218
228
  return queryDoc({
219
229
  slug,
220
230
  locale,
231
+ depth,
221
232
  collectionSlug
222
233
  });
223
234
  }
@@ -274,7 +285,10 @@ function createCollectionPageExports({
274
285
  await props.params;
275
286
  const perLocaleEntries = await Promise.all(routing.locales.map(async (locale) => {
276
287
  const docs = await queryAllDocs({ locale, collectionSlug });
277
- return docs.filter((doc) => typeof doc.slug === "string" && doc.slug.length > 0).map((doc) => ({ locale, slug: slugToParamsSlug(doc.slug, slugShape) }));
288
+ const entries = docs.filter((doc) => !isIndexSlug(doc.slug)).map((doc) => ({ locale, slug: slugToParamsSlug(doc.slug, slugShape) }));
289
+ if (shapeHasIndexPath(slugShape) && await fetchDoc(locale, ""))
290
+ entries.push({ locale, slug: slugToParamsSlug("", slugShape) });
291
+ return entries;
278
292
  }));
279
293
  return perLocaleEntries.flat();
280
294
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justanarthur/payload-www",
3
3
  "description": "Reusable Payload CMS website template — config builder, collections, globals, blocks, fields, access, hooks, metadata (JSON-LD, hreflang), page renderers, and test helpers.",
4
- "version": "2.2.7",
4
+ "version": "2.2.9",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "files": [