@justanarthur/payload-www 0.3.5 → 1.2.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.
Files changed (63) hide show
  1. package/README.md +317 -307
  2. package/dist/access.d.ts +2 -2
  3. package/dist/access.js +3 -17
  4. package/dist/blocks.d.ts +7 -12
  5. package/dist/blocks.js +24 -43
  6. package/dist/cli.js +201 -0
  7. package/dist/collections.d.ts +33 -225
  8. package/dist/collections.js +185 -639
  9. package/dist/config.d.ts +19 -105
  10. package/dist/config.js +257 -855
  11. package/dist/fields.d.ts +4 -46
  12. package/dist/fields.js +177 -53
  13. package/dist/imagehash.js +0 -15
  14. package/dist/import-map-provider.d.ts +0 -16
  15. package/dist/import-map-provider.js +0 -15
  16. package/dist/metadata.d.ts +24 -89
  17. package/dist/metadata.js +123 -255
  18. package/dist/pages.d.ts +37 -319
  19. package/dist/pages.js +349 -964
  20. package/dist/render-pages.d.ts +70 -565
  21. package/dist/render-pages.js +464 -1477
  22. package/dist/sitemap.d.ts +10 -0
  23. package/dist/sitemap.js +337 -0
  24. package/dist/translator.js +0 -15
  25. package/dist/utils.d.ts +10 -12
  26. package/dist/utils.js +18 -41
  27. package/package.json +81 -178
  28. package/dist/components.d.ts +0 -6
  29. package/dist/components.js +0 -39
  30. package/dist/core-access.d.ts +0 -11
  31. package/dist/core-access.js +0 -34
  32. package/dist/core-blocks.d.ts +0 -24
  33. package/dist/core-blocks.js +0 -79
  34. package/dist/core-fields.d.ts +0 -73
  35. package/dist/core-fields.js +0 -167
  36. package/dist/core-utils.d.ts +0 -16
  37. package/dist/core-utils.js +0 -63
  38. package/dist/data-collections.d.ts +0 -229
  39. package/dist/data-collections.js +0 -676
  40. package/dist/data-seed.d.ts +0 -76
  41. package/dist/data-seed.js +0 -212
  42. package/dist/data-test.d.ts +0 -30
  43. package/dist/data-test.js +0 -1110
  44. package/dist/globals.d.ts +0 -69
  45. package/dist/globals.js +0 -251
  46. package/dist/hooks.d.ts +0 -108
  47. package/dist/hooks.js +0 -228
  48. package/dist/index.d.ts +0 -6
  49. package/dist/index.js +0 -39
  50. package/dist/render-components.d.ts +0 -42
  51. package/dist/render-components.js +0 -154
  52. package/dist/render-metadata.d.ts +0 -122
  53. package/dist/render-metadata.js +0 -390
  54. package/dist/render-utils.d.ts +0 -166
  55. package/dist/render-utils.js +0 -398
  56. package/dist/seed.d.ts +0 -76
  57. package/dist/seed.js +0 -212
  58. package/dist/server.d.ts +0 -980
  59. package/dist/server.js +0 -2231
  60. package/dist/test.d.ts +0 -30
  61. package/dist/test.js +0 -1110
  62. package/dist/with-www-config.d.ts +0 -108
  63. package/dist/with-www-config.js +0 -1006
package/dist/pages.js CHANGED
@@ -1,284 +1,20 @@
1
1
 
2
- var __defProp = Object.defineProperty;
3
- var __returnValue = (v) => v;
4
- function __exportSetter(name, newValue) {
5
- this[name] = __returnValue.bind(null, newValue);
6
- }
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, {
10
- get: all[name],
11
- enumerable: true,
12
- configurable: true,
13
- set: __exportSetter.bind(all, name)
14
- });
15
- };
16
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
-
18
- // src/render/components/PageShowcase.tsx
19
- var exports_PageShowcase = {};
20
- __export(exports_PageShowcase, {
21
- PageShowcase: () => PageShowcase
22
- });
23
- import * as React from "react";
24
- import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
25
- function PageShowcase({
26
- children,
27
- metadata,
28
- jsonLd,
29
- localeSwitcher,
30
- metadataHeading = "Page metadata",
31
- jsonLdHeading = "JSON-LD"
32
- }) {
33
- console.log("[WWW] render/components:PageShowcase jsonLdEntries=", jsonLd.length, "hasOg=", Boolean(metadata.openGraph), "hasTwitter=", Boolean(metadata.twitter), "canonical=", metadata.alternates?.canonical);
34
- const og = metadata.openGraph;
35
- const twitter = metadata.twitter;
36
- const rows = [
37
- ["Title", resolveTitle(metadata.title)],
38
- ["Description", metadata.description],
39
- ["Canonical", metadata.alternates?.canonical],
40
- [
41
- "Languages",
42
- metadata.alternates?.languages ? Object.entries(metadata.alternates.languages).map(([locale, url]) => `${locale}: ${url}`).join(`
43
- `) : undefined
44
- ],
45
- ["Open Graph title", og?.title],
46
- ["Open Graph description", og?.description],
47
- ["Open Graph type", og?.type],
48
- ["Open Graph url", og?.url],
49
- ["Open Graph site name", og?.siteName],
50
- ["Twitter card", twitter?.card],
51
- ["Twitter title", twitter?.title],
52
- ["Twitter description", twitter?.description],
53
- ["Twitter site", twitter?.site],
54
- ["Twitter creator", twitter?.creator]
55
- ];
56
- return /* @__PURE__ */ jsxs3("div", {
57
- className: "page-showcase grid gap-8 lg:grid-cols-[1fr_320px]",
58
- children: [
59
- /* @__PURE__ */ jsx6("main", {
60
- className: "page-showcase__main",
61
- children
62
- }),
63
- /* @__PURE__ */ jsxs3("aside", {
64
- className: "page-showcase__sidebar flex flex-col gap-6 text-sm",
65
- children: [
66
- /* @__PURE__ */ jsxs3("section", {
67
- className: "page-showcase__locale",
68
- children: [
69
- /* @__PURE__ */ jsx6("h2", {
70
- className: "m-0 mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",
71
- children: "Language"
72
- }),
73
- localeSwitcher
74
- ]
75
- }),
76
- /* @__PURE__ */ jsxs3("section", {
77
- className: "page-showcase__metadata",
78
- children: [
79
- /* @__PURE__ */ jsx6("h2", {
80
- className: "m-0 mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",
81
- children: metadataHeading
82
- }),
83
- /* @__PURE__ */ jsx6("dl", {
84
- className: "m-0 grid grid-cols-[max-content_1fr] gap-x-3 gap-y-1.5",
85
- children: rows.filter(([, value]) => value !== undefined && value !== "").map(([label, value]) => /* @__PURE__ */ jsxs3(React.Fragment, {
86
- children: [
87
- /* @__PURE__ */ jsx6("dt", {
88
- className: "font-medium text-muted-foreground",
89
- children: label
90
- }),
91
- /* @__PURE__ */ jsx6("dd", {
92
- className: "m-0 whitespace-pre-wrap break-words font-mono text-xs",
93
- children: value
94
- })
95
- ]
96
- }, label))
97
- })
98
- ]
99
- }),
100
- jsonLd.length > 0 ? /* @__PURE__ */ jsxs3("section", {
101
- className: "page-showcase__jsonld",
102
- children: [
103
- /* @__PURE__ */ jsx6("h2", {
104
- className: "m-0 mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",
105
- children: jsonLdHeading
106
- }),
107
- jsonLd.map(({ id, schema }) => /* @__PURE__ */ jsxs3("details", {
108
- className: "mb-2 rounded border border-border bg-muted/30 p-2",
109
- children: [
110
- /* @__PURE__ */ jsx6("summary", {
111
- className: "cursor-pointer font-mono text-xs",
112
- children: id
113
- }),
114
- /* @__PURE__ */ jsx6("pre", {
115
- className: "mt-2 overflow-x-auto whitespace-pre-wrap break-words font-mono text-[10px] leading-snug",
116
- children: JSON.stringify(schema, null, 2)
117
- })
118
- ]
119
- }, id))
120
- ]
121
- }) : null
122
- ]
123
- })
124
- ]
125
- });
126
- }
127
- function resolveTitle(title) {
128
- if (!title)
129
- return;
130
- if (typeof title === "string")
131
- return title;
132
- if (title === null)
133
- return;
134
- const t = title;
135
- return t.absolute ?? t.template ?? t.default;
136
- }
137
- var init_PageShowcase = () => {};
138
-
139
- // src/render/components/LocaleSwitcher.tsx
140
- var exports_LocaleSwitcher = {};
141
- __export(exports_LocaleSwitcher, {
142
- LocaleSwitcher: () => LocaleSwitcher
143
- });
144
- import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
145
- function LocaleSwitcher({
146
- currentLocale,
147
- hreflangAlternates,
148
- labels
149
- }) {
150
- const locales = Object.keys(hreflangAlternates).filter((k) => k !== "x-default");
151
- console.log("[WWW] render/components:LocaleSwitcher currentLocale=", currentLocale, "locales=", JSON.stringify(locales), "hasXDefault=", Boolean(hreflangAlternates["x-default"]));
152
- return /* @__PURE__ */ jsx7("nav", {
153
- "aria-label": "Language",
154
- className: "locale-switcher",
155
- children: /* @__PURE__ */ jsxs4("ul", {
156
- className: "flex flex-wrap gap-2 list-none p-0 m-0",
157
- children: [
158
- locales.map((locale) => {
159
- const href = hreflangAlternates[locale];
160
- if (!href)
161
- return null;
162
- const isCurrent = locale === currentLocale;
163
- return /* @__PURE__ */ jsx7("li", {
164
- children: /* @__PURE__ */ jsx7("a", {
165
- href,
166
- "aria-current": isCurrent ? "true" : undefined,
167
- hrefLang: locale,
168
- className: "locale-switcher__link",
169
- "data-locale": locale,
170
- children: labels?.[locale] ?? locale.toUpperCase()
171
- })
172
- }, locale);
173
- }),
174
- hreflangAlternates["x-default"] ? /* @__PURE__ */ jsx7("li", {
175
- children: /* @__PURE__ */ jsx7("a", {
176
- href: hreflangAlternates["x-default"],
177
- hrefLang: "x-default",
178
- className: "locale-switcher__link",
179
- "data-locale": "x-default",
180
- children: labels?.["x-default"] ?? "Default"
181
- })
182
- }, "x-default") : null
183
- ]
184
- })
185
- });
186
- }
187
- var init_LocaleSwitcher = () => {};
188
-
189
- // src/core/utils/getFromImportMap.ts
190
- function getFromImportMap(key, importMap) {
191
- return importMap[key.includes("#") ? key : key + "#default"];
192
- }
193
-
194
- // src/core/utils/generateImportName.ts
195
- function generateImportName(type, slug) {
196
- switch (type) {
197
- case "block":
198
- return `Block${slug.replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase())}#default`;
199
- case "page":
200
- return `Page${slug.replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase())}#default`;
201
- default:
202
- throw new Error(`Unknown type: ${type}`);
203
- }
204
- }
205
-
206
- // src/render/blocks/renderBlocks.tsx
207
- import { jsx, Fragment } from "react/jsx-runtime";
208
- var RenderBlocks = ({
209
- blocks,
210
- blockProps,
211
- config,
212
- importMap,
213
- locale,
214
- searchParams
215
- }) => {
216
- if (!blocks || !Array.isArray(blocks) || blocks.length === 0) {
217
- console.log("[WWW] render/blocks:RenderBlocks no blocks (locale=", locale, ")");
218
- return null;
219
- }
220
- console.log("[WWW] render/blocks:RenderBlocks rendering count=", blocks.length, "locale=", locale);
221
- const rendered = [];
222
- for (let i = 0;i < blocks.length; i++) {
223
- const block = blocks[i];
224
- const { blockType } = block;
225
- const importMapPath = config.admin?.dependencies?.[blockType]?.path ?? generateImportName("block", blockType);
226
- const Block = getFromImportMap(importMapPath, importMap);
227
- if (!Block) {
228
- console.warn(`[WWW] render/blocks:RenderBlocks no block for type=${blockType} importMapPath=${importMapPath} (locale=${locale})`);
229
- continue;
230
- }
231
- console.log("[WWW] render/blocks:RenderBlocks [", i, "] blockType=", blockType, "importMapPath=", importMapPath);
232
- rendered.push(/* @__PURE__ */ jsx(Block, {
233
- index: i,
234
- ...blockProps,
235
- ...block,
236
- locale,
237
- searchParams
238
- }, i));
239
- }
240
- return /* @__PURE__ */ jsx(Fragment, {
241
- children: rendered
242
- });
243
- };
244
-
245
- // src/render/pages/PagesPage.tsx
246
- import { jsx as jsx2, Fragment as Fragment2 } from "react/jsx-runtime";
247
- async function PagesPage({ doc, ...props }) {
248
- if (!doc) {
249
- console.log("[WWW] render/pages:PagesPage no doc");
250
- return /* @__PURE__ */ jsx2(Fragment2, {});
251
- }
252
- const blocks = doc.blocks ?? [];
253
- console.log("[WWW] render/pages:PagesPage blocks=", blocks.length, "locale=", props.locale);
254
- return /* @__PURE__ */ jsx2(Fragment2, {
255
- children: /* @__PURE__ */ jsx2(RenderBlocks, {
256
- blocks,
257
- ...props
258
- })
259
- });
260
- }
261
2
 
262
- // src/render/pages/HeaderPage.tsx
3
+ // src/render/pages/FooterPage.tsx
263
4
  import"server-only";
264
- import { jsx as jsx3, jsxs, Fragment as Fragment3 } from "react/jsx-runtime";
265
- function HeaderPage({ data, locale: _locale }) {
266
- if (!data) {
267
- console.log("[WWW] render/pages:HeaderPage no data");
268
- return /* @__PURE__ */ jsx3(Fragment3, {});
269
- }
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ function FooterPage({ data }) {
270
7
  const nav = data.nav ?? [];
271
8
  const items = nav.filter((b) => b.blockType === "navItem");
272
9
  const columns = nav.filter((b) => b.blockType === "navColumn");
273
- console.log("[WWW] render/pages:HeaderPage items=", items.length, "columns=", columns.length, "locale=", _locale);
274
10
  const renderLink = (link, fallbackHref = "#") => {
275
11
  if (!link)
276
- return /* @__PURE__ */ jsx3("a", {
12
+ return /* @__PURE__ */ jsx("a", {
277
13
  href: fallbackHref,
278
14
  children: link?.label ?? ""
279
15
  });
280
16
  if (link.type === "custom" && typeof link.url === "string") {
281
- return /* @__PURE__ */ jsx3("a", {
17
+ return /* @__PURE__ */ jsx("a", {
282
18
  href: link.url,
283
19
  children: link.label
284
20
  });
@@ -286,60 +22,57 @@ function HeaderPage({ data, locale: _locale }) {
286
22
  if (link.type === "reference" && link.reference) {
287
23
  const ref = link.reference;
288
24
  if (typeof ref === "object" && ref.slug) {
289
- return /* @__PURE__ */ jsx3("a", {
25
+ return /* @__PURE__ */ jsx("a", {
290
26
  href: `/${ref.slug}`,
291
27
  children: link.label
292
28
  });
293
29
  }
294
30
  }
295
- return /* @__PURE__ */ jsx3("a", {
31
+ return /* @__PURE__ */ jsx("a", {
296
32
  href: fallbackHref,
297
33
  children: link.label ?? ""
298
34
  });
299
35
  };
300
- return /* @__PURE__ */ jsxs("nav", {
301
- children: [
302
- items.map((item, i) => /* @__PURE__ */ jsx3("span", {
303
- style: { marginRight: 16 },
304
- children: renderLink(item.link)
305
- }, `item-${i}`)),
306
- columns.map((col, i) => /* @__PURE__ */ jsxs("div", {
307
- style: { display: "inline-block", marginRight: 24, verticalAlign: "top" },
308
- children: [
309
- col.title ? /* @__PURE__ */ jsx3("strong", {
310
- children: col.title
311
- }) : null,
312
- /* @__PURE__ */ jsx3("div", {
313
- children: (col.links ?? []).map((entry, j) => /* @__PURE__ */ jsx3("div", {
314
- children: renderLink(entry.link)
315
- }, `col-${i}-link-${j}`))
316
- })
317
- ]
318
- }, `col-${i}`))
319
- ]
36
+ return /* @__PURE__ */ jsx("footer", {
37
+ children: /* @__PURE__ */ jsxs("div", {
38
+ children: [
39
+ items.map((item, i) => /* @__PURE__ */ jsx("span", {
40
+ style: { marginRight: 16 },
41
+ children: renderLink(item.link)
42
+ }, `item-${i}`)),
43
+ columns.map((col, i) => /* @__PURE__ */ jsxs("div", {
44
+ style: { display: "inline-block", marginRight: 24, verticalAlign: "top" },
45
+ children: [
46
+ col.title ? /* @__PURE__ */ jsx("strong", {
47
+ children: col.title
48
+ }) : null,
49
+ /* @__PURE__ */ jsx("div", {
50
+ children: (col.links ?? []).map((entry, j) => /* @__PURE__ */ jsx("div", {
51
+ children: renderLink(entry.link)
52
+ }, `col-${i}-link-${j}`))
53
+ })
54
+ ]
55
+ }, `col-${i}`))
56
+ ]
57
+ })
320
58
  });
321
59
  }
322
60
 
323
- // src/render/pages/FooterPage.tsx
61
+ // src/render/pages/HeaderPage.tsx
324
62
  import"server-only";
325
- import { jsx as jsx4, jsxs as jsxs2, Fragment as Fragment4 } from "react/jsx-runtime";
326
- function FooterPage({ data, locale: _locale }) {
327
- if (!data) {
328
- console.log("[WWW] render/pages:FooterPage no data");
329
- return /* @__PURE__ */ jsx4(Fragment4, {});
330
- }
63
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
64
+ function HeaderPage({ data }) {
331
65
  const nav = data.nav ?? [];
332
66
  const items = nav.filter((b) => b.blockType === "navItem");
333
67
  const columns = nav.filter((b) => b.blockType === "navColumn");
334
- console.log("[WWW] render/pages:FooterPage items=", items.length, "columns=", columns.length, "locale=", _locale);
335
68
  const renderLink = (link, fallbackHref = "#") => {
336
69
  if (!link)
337
- return /* @__PURE__ */ jsx4("a", {
70
+ return /* @__PURE__ */ jsx2("a", {
338
71
  href: fallbackHref,
339
72
  children: link?.label ?? ""
340
73
  });
341
74
  if (link.type === "custom" && typeof link.url === "string") {
342
- return /* @__PURE__ */ jsx4("a", {
75
+ return /* @__PURE__ */ jsx2("a", {
343
76
  href: link.url,
344
77
  children: link.label
345
78
  });
@@ -347,284 +80,167 @@ function FooterPage({ data, locale: _locale }) {
347
80
  if (link.type === "reference" && link.reference) {
348
81
  const ref = link.reference;
349
82
  if (typeof ref === "object" && ref.slug) {
350
- return /* @__PURE__ */ jsx4("a", {
83
+ return /* @__PURE__ */ jsx2("a", {
351
84
  href: `/${ref.slug}`,
352
85
  children: link.label
353
86
  });
354
87
  }
355
88
  }
356
- return /* @__PURE__ */ jsx4("a", {
89
+ return /* @__PURE__ */ jsx2("a", {
357
90
  href: fallbackHref,
358
91
  children: link.label ?? ""
359
92
  });
360
93
  };
361
- return /* @__PURE__ */ jsx4("footer", {
362
- children: /* @__PURE__ */ jsxs2("div", {
363
- children: [
364
- items.map((item, i) => /* @__PURE__ */ jsx4("span", {
365
- style: { marginRight: 16 },
366
- children: renderLink(item.link)
367
- }, `item-${i}`)),
368
- columns.map((col, i) => /* @__PURE__ */ jsxs2("div", {
369
- style: { display: "inline-block", marginRight: 24, verticalAlign: "top" },
370
- children: [
371
- col.title ? /* @__PURE__ */ jsx4("strong", {
372
- children: col.title
373
- }) : null,
374
- /* @__PURE__ */ jsx4("div", {
375
- children: (col.links ?? []).map((entry, j) => /* @__PURE__ */ jsx4("div", {
376
- children: renderLink(entry.link)
377
- }, `col-${i}-link-${j}`))
378
- })
379
- ]
380
- }, `col-${i}`))
381
- ]
382
- })
94
+ return /* @__PURE__ */ jsxs2("nav", {
95
+ children: [
96
+ items.map((item, i) => /* @__PURE__ */ jsx2("span", {
97
+ style: { marginRight: 16 },
98
+ children: renderLink(item.link)
99
+ }, `item-${i}`)),
100
+ columns.map((col, i) => /* @__PURE__ */ jsxs2("div", {
101
+ style: { display: "inline-block", marginRight: 24, verticalAlign: "top" },
102
+ children: [
103
+ col.title ? /* @__PURE__ */ jsx2("strong", {
104
+ children: col.title
105
+ }) : null,
106
+ /* @__PURE__ */ jsx2("div", {
107
+ children: (col.links ?? []).map((entry, j) => /* @__PURE__ */ jsx2("div", {
108
+ children: renderLink(entry.link)
109
+ }, `col-${i}-link-${j}`))
110
+ })
111
+ ]
112
+ }, `col-${i}`))
113
+ ]
383
114
  });
384
115
  }
385
116
 
386
- // src/render/pages/createCollectionPageExports.tsx
387
- import"server-only";
388
- import { Suspense } from "react";
117
+ // src/render/getFromImportMap.ts
118
+ function getFromImportMap(key, importMap) {
119
+ if (!key)
120
+ return;
121
+ const entry = importMap[key.includes("#") ? key : `${key}#default`];
122
+ if (entry == null)
123
+ return;
124
+ if (typeof entry === "function") {
125
+ return entry().then((mod) => {
126
+ if (typeof mod === "function")
127
+ return mod;
128
+ const modObj = mod;
129
+ return modObj.default ?? mod;
130
+ });
131
+ }
132
+ return entry;
133
+ }
389
134
 
390
- // src/config/constants.ts
391
- var PAGES_RENDER_PATH = "@justanarthur/payload-www/render-pages#PagesPage";
392
- var POSTS_RENDER_PATH = "@justanarthur/payload-www/render-pages#PostsPage";
393
- var HEADER_RENDER_PATH = "@justanarthur/payload-www/render-pages#HeaderPage";
394
- var FOOTER_RENDER_PATH = "@justanarthur/payload-www/render-pages#FooterPage";
395
- var LIVE_PREVIEW_LISTENER_PATH = "@justanarthur/payload-www/render-components#LivePreviewListener";
396
- var PAGES_SLUG = "pages";
397
- var POSTS_SLUG = "posts";
398
- var STATIC_PAGES_SLUG = "staticPages";
135
+ // package.json
136
+ var name = "@justanarthur/payload-www";
399
137
 
400
- // src/render/utils/renderCollectionModule.tsx
401
- import { jsx as jsx5 } from "react/jsx-runtime";
402
- function renderCollectionModule(collection = [], slug, importMap, props) {
403
- const renderPath = collection?.find((c) => c.slug === slug)?.custom?.path;
404
- if (!renderPath) {
405
- console.log("[WWW] render/utils:renderCollectionModule no custom.path slug=", slug);
406
- return null;
407
- }
408
- const CollectionRenderModule = getFromImportMap(renderPath, importMap);
409
- if (!CollectionRenderModule) {
410
- console.error("[WWW] render/utils:renderCollectionModule not found slug=", slug, "path=", renderPath);
411
- if (false) {}
138
+ // src/render/blocks/renderBlocks.tsx
139
+ import { jsx as jsx3, Fragment } from "react/jsx-runtime";
140
+ var DEFAULT_BLOCK_PATH_PREFIX = "@/components/blocks";
141
+ var RenderBlocks = async ({ blocks, blockProps, config, importMap, locale, searchParams }) => {
142
+ if (!blocks || !Array.isArray(blocks) || blocks.length === 0)
412
143
  return null;
144
+ const rendered = [];
145
+ for (let i = 0;i < blocks.length; i++) {
146
+ const block = blocks[i];
147
+ const { blockType } = block;
148
+ const blockConfig = (config.blocks ?? []).find((b) => b.slug === blockType);
149
+ const customPath = blockConfig?.custom?.[name]?.path;
150
+ const importMapPath = (typeof customPath === "string" ? customPath : null) ?? `${DEFAULT_BLOCK_PATH_PREFIX}/${blockType}`;
151
+ const Block = await getFromImportMap(importMapPath, importMap);
152
+ if (!Block) {
153
+ console.warn(`[WWW] render/blocks:RenderBlocks no block for type=${blockType} importMapPath=${importMapPath} (locale=${locale})`);
154
+ continue;
155
+ }
156
+ rendered.push(/* @__PURE__ */ jsx3(Block, {
157
+ index: i,
158
+ ...blockProps,
159
+ ...block,
160
+ locale,
161
+ searchParams
162
+ }, i));
413
163
  }
414
- console.log("[WWW] render/utils:renderCollectionModule rendering slug=", slug, "path=", renderPath);
415
- return /* @__PURE__ */ jsx5(CollectionRenderModule, {
416
- importMap,
164
+ return /* @__PURE__ */ jsx3(Fragment, {
165
+ children: rendered
166
+ });
167
+ };
168
+
169
+ // src/render/pages/PagesPage.tsx
170
+ import { jsx as jsx4 } from "react/jsx-runtime";
171
+ async function PagesPage({ data, locale, ...props }) {
172
+ const blocks = data.blocks ?? [];
173
+ return /* @__PURE__ */ jsx4(RenderBlocks, {
174
+ blocks,
175
+ locale,
417
176
  ...props
418
177
  });
419
178
  }
420
179
 
421
- // src/render/metadata/hreflang.ts
422
- async function buildHreflangAlternates({
423
- siteUrl,
424
- locale,
425
- urlPrefix,
426
- storedSlug,
427
- queryAllLocaleSlugs,
428
- nested,
429
- homeSlug,
430
- defaultLocale,
431
- locales,
432
- localePrefix = "always"
433
- }) {
434
- const allLocaleSlugs = await queryAllLocaleSlugs(storedSlug, locale);
435
- console.log("[WWW] render/metadata:buildHreflangAlternates storedSlug=", storedSlug, "locale=", locale, "allLocaleSlugs=", JSON.stringify(allLocaleSlugs));
436
- const languages = {};
437
- const urlFor = (l, slug) => {
438
- const trimmedPrefix = urlPrefix.replace(/^\/|\/$/g, "");
439
- const prefixSegment = trimmedPrefix ? `/${trimmedPrefix}` : "";
440
- const urlPath = slug === homeSlug ? "/" : nested ? "/" + slug.replaceAll("_", "/") : "/" + slug;
441
- const localeSegment = localePrefix === "never" ? "" : localePrefix === "as-needed" && l === defaultLocale ? "" : `/${l}`;
442
- return `${siteUrl}${localeSegment}${prefixSegment}${urlPath}`;
443
- };
444
- for (const l of locales) {
445
- const slugForLocale = allLocaleSlugs?.[l];
446
- if (!slugForLocale)
447
- continue;
448
- languages[l] = urlFor(l, slugForLocale);
449
- }
450
- if (allLocaleSlugs?.[defaultLocale]) {
451
- languages["x-default"] = urlFor(defaultLocale, allLocaleSlugs[defaultLocale]);
452
- }
453
- console.log("[WWW] render/metadata:buildHreflangAlternates ->", JSON.stringify(languages));
454
- return languages;
455
- }
180
+ // src/render/pages/createCollectionPageExports.tsx
181
+ import"server-only";
456
182
 
457
- // src/render/metadata/jsonld.ts
458
- function getImageUrl(doc, siteUrl) {
459
- const img = doc?.meta?.image ?? doc?.heroImage ?? doc?.image;
460
- if (!img)
461
- return null;
462
- if (typeof img === "string")
463
- return img;
464
- if (img?.url)
465
- return img.url.startsWith("http") ? img.url : `${siteUrl}${img.url}`;
466
- return null;
467
- }
468
- function getImageUrlWithLog(doc, siteUrl) {
469
- const result = getImageUrl(doc, siteUrl);
470
- console.log("[WWW] render/metadata:jsonld:getImageUrl ->", result);
471
- return result;
472
- }
473
- function resolveLocalizedField(value, locale) {
474
- if (value == null)
475
- return "";
476
- if (typeof value === "string") {
477
- if (!value.startsWith("{"))
478
- return value;
479
- try {
480
- const parsed = JSON.parse(value);
481
- return resolveLocalizedField(parsed, locale);
482
- } catch {
483
- return value;
484
- }
485
- }
486
- if (typeof value !== "object")
183
+ // src/render/metadata/slug.ts
184
+ var SLUG_NESTED_DIVIDER = "_";
185
+ function paramsSlugToSlug(slug, _shape) {
186
+ if (!slug)
487
187
  return "";
488
- const obj = value;
489
- if (typeof obj[locale] === "string" && obj[locale].length > 0) {
490
- return obj[locale];
491
- }
492
- return Object.values(obj).filter((v) => typeof v === "string" && v.length > 0).join(" / ");
188
+ return (Array.isArray(slug) ? slug : [slug]).join(SLUG_NESTED_DIVIDER);
493
189
  }
494
- function resolveLocalizedFieldWithLog(value, locale) {
495
- const result = resolveLocalizedField(value, locale);
496
- if (value && typeof value === "object") {
497
- console.log("[WWW] render/metadata:jsonld:resolveLocalizedField locale=", locale, "->", JSON.stringify(result));
498
- }
499
- return result;
500
- }
501
- function buildArticleLd({
502
- doc,
503
- url,
504
- locale,
505
- siteUrl,
506
- type = "BlogPosting",
507
- publisherName,
508
- publisherLogo
509
- }) {
510
- const name = publisherName ?? new URL(siteUrl).hostname;
511
- console.log("[WWW] render/metadata:buildArticleLd url=", url, "locale=", locale, "type=", type, "publisherName=", name);
512
- const ld = {
513
- "@context": "https://schema.org",
514
- "@type": type,
515
- "@id": `${url}#article`,
516
- headline: resolveLocalizedFieldWithLog(doc.title, locale),
517
- description: resolveLocalizedFieldWithLog(doc.meta?.description ?? doc.description ?? doc.excerpt, locale),
518
- inLanguage: locale,
519
- url,
520
- dateModified: doc.updatedAt ? new Date(doc.updatedAt).toISOString() : undefined
521
- };
522
- const datePublished = doc.publishedAt ?? doc.createdAt;
523
- if (datePublished)
524
- ld.datePublished = new Date(datePublished).toISOString();
525
- const imgUrl = getImageUrlWithLog(doc, siteUrl);
526
- if (imgUrl)
527
- ld.image = imgUrl;
528
- ld.author = { "@type": "Organization", name, url: siteUrl };
529
- const publisher = { "@type": "Organization", name };
530
- if (publisherLogo !== undefined) {
531
- if (publisherLogo !== null)
532
- publisher.logo = { "@type": "ImageObject", url: publisherLogo };
533
- }
534
- ld.publisher = publisher;
535
- return ld;
190
+ function slugToParamsSlug(slug, shape) {
191
+ if (!slug)
192
+ return shape === "catch-all" ? [] : "";
193
+ return shape === "catch-all" ? slug.split(SLUG_NESTED_DIVIDER) : slug;
536
194
  }
537
- function buildBreadcrumbsLd({
538
- items,
539
- currentUrl
540
- }) {
541
- console.log("[WWW] render/metadata:buildBreadcrumbsLd items=", items.length, "currentUrl=", currentUrl);
542
- return {
543
- "@context": "https://schema.org",
544
- "@type": "BreadcrumbList",
545
- itemListElement: items.map((item, index) => ({
546
- "@type": "ListItem",
547
- position: index + 1,
548
- name: item.label,
549
- item: index === items.length - 1 ? currentUrl : item.url
550
- }))
195
+
196
+ // src/render/metadata/query.ts
197
+ import { getPayload } from "payload";
198
+
199
+ // src/collections/hooks/createRevalidateCollectionGlobalHook.ts
200
+ import { revalidateTag } from "next/cache";
201
+ function createRevalidateCollectionGlobalHook() {
202
+ const afterChangeDeleteHook = async ({ doc, req, ...args }) => {
203
+ const previousDoc = "previousDoc" in args ? args.previousDoc : null, locale = req.locale;
204
+ function revalidate(args2) {
205
+ try {
206
+ revalidateTag(createCollectionCacheKey({ ...args2, locale }), "max");
207
+ } catch (error) {
208
+ const msg = error instanceof Error ? error.message : String(error);
209
+ if (msg.includes("static generation store missing"))
210
+ return;
211
+ console.error(error);
212
+ }
213
+ }
214
+ if ("collection" in args) {
215
+ [
216
+ doc && doc._status !== "draft" && doc.slug,
217
+ previousDoc && previousDoc._status === "published" && previousDoc.slug
218
+ ].filter((slug) => slug !== undefined && slug !== false).map((slug) => revalidate({ collectionSlug: args.collection.slug, slug }));
219
+ } else {
220
+ revalidate({ globalSlug: args.global.slug });
221
+ }
222
+ return doc;
551
223
  };
224
+ return { afterChange: afterChangeDeleteHook, afterDelete: afterChangeDeleteHook };
552
225
  }
553
- function buildOrganizationLd({
554
- siteUrl,
555
- name,
556
- logo,
557
- sameAs
558
- }) {
559
- console.log("[WWW] render/metadata:buildOrganizationLd siteUrl=", siteUrl, "name=", name, "logo?", Boolean(logo), "sameAs?", Boolean(sameAs));
560
- const org = {
561
- "@context": "https://schema.org",
562
- "@type": "Organization",
563
- "@id": `${siteUrl}#organization`,
564
- url: siteUrl,
565
- ...name && { name },
566
- ...logo && { logo: { "@type": "ImageObject", url: logo } },
567
- ...sameAs && sameAs.length > 0 && { sameAs }
568
- };
569
- return org;
226
+ function createCollectionCacheKey(args) {
227
+ return `${"globalSlug" in args ? args.globalSlug : args.collectionSlug + args.slug}_${args.locale}`;
570
228
  }
571
229
 
572
- // src/render/metadata/slug.ts
573
- var SLUG_NESTED_DIVIDER = "_";
574
- function segmentsToStoredSlug(segments, nested) {
575
- if (!Array.isArray(segments)) {
576
- console.log("[WWW] render/metadata:segmentsToStoredSlug string passthrough:", JSON.stringify(segments));
577
- return segments;
578
- }
579
- const result = nested ? segments.join(SLUG_NESTED_DIVIDER) : segments[0] ?? "";
580
- console.log("[WWW] render/metadata:segmentsToStoredSlug nested=", nested, "segments=", JSON.stringify(segments), "->", result);
581
- return result;
582
- }
583
- function segmentsToUrlPath(segments, nested) {
584
- let result;
585
- if (!Array.isArray(segments))
586
- result = "/" + segments;
587
- else if (nested)
588
- result = "/" + segments.join("/");
589
- else
590
- result = "/" + (segments[0] ?? "");
591
- console.log("[WWW] render/metadata:segmentsToUrlPath nested=", nested, "segments=", JSON.stringify(segments), "->", result);
592
- return result;
593
- }
594
- function storedSlugToSegments(storedSlug, nested) {
595
- const result = nested ? storedSlug.split(SLUG_NESTED_DIVIDER) : storedSlug;
596
- console.log("[WWW] render/metadata:storedSlugToSegments nested=", nested, "storedSlug=", storedSlug, "->", JSON.stringify(result));
597
- return result;
598
- }
599
- function buildCanonicalUrl({
600
- siteUrl,
601
- locale,
602
- urlPrefix,
603
- urlPath
604
- }) {
605
- const trimmedPrefix = urlPrefix.replace(/^\/|\/$/g, "");
606
- const prefixSegment = trimmedPrefix ? `/${trimmedPrefix}` : "";
607
- const result = `${siteUrl}/${locale}${prefixSegment}${urlPath}`;
608
- console.log("[WWW] render/metadata:buildCanonicalUrl siteUrl=", siteUrl, "locale=", locale, "urlPrefix=", urlPrefix, "urlPath=", urlPath, "->", result);
609
- return result;
230
+ // src/render/metadata/query.ts
231
+ async function withUnstableCache(keyParts, tags, fn) {
232
+ const { unstable_cache } = await import("next/cache");
233
+ return unstable_cache(fn, keyParts.map(String), { tags })();
610
234
  }
611
- function getUrlPath(segments, nested, homeSlug) {
612
- const urlPath = segmentsToUrlPath(segments, nested);
613
- if (nested && !Array.isArray(segments)) {
614
- if (segments === homeSlug)
615
- return "/";
616
- } else if (nested && Array.isArray(segments)) {
617
- const stored = segments.join(SLUG_NESTED_DIVIDER);
618
- if (stored === homeSlug)
619
- return "/";
620
- }
621
- return urlPath;
235
+ async function queryDoc(args, { config: configPromise }) {
236
+ return withUnstableCache(Object.values(args), [createCollectionCacheKey(args)], async () => {
237
+ if ("globalSlug" in args)
238
+ return queryGlobal({ ...args, config: configPromise });
239
+ else
240
+ return queryDocBySlug({ ...args, config: configPromise });
241
+ });
622
242
  }
623
-
624
- // src/render/metadata/query.ts
625
- import { getPayload } from "payload";
626
- import { cache } from "react";
627
- var queryDocBySlug = cache(async function queryDocBySlug2({
243
+ async function queryDocBySlug({
628
244
  collectionSlug,
629
245
  slug,
630
246
  slugField = "slug",
@@ -632,480 +248,249 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
632
248
  draft = false,
633
249
  config
634
250
  }) {
635
- console.log("[WWW] render/metadata:queryDocBySlug collection=", collectionSlug, "slug=", slug, "slugField=", slugField, "locale=", locale, "draft=", draft);
636
- const payload = await getPayload({ config });
637
- const result = await payload.find({
638
- collection: collectionSlug,
639
- draft,
640
- limit: 1,
641
- pagination: false,
642
- overrideAccess: draft,
643
- where: { [slugField]: { equals: slug } },
644
- locale
251
+ return withUnstableCache([collectionSlug, slug, locale, draft], [createCollectionCacheKey({ collectionSlug, slug, locale })], async () => {
252
+ const payload = await getPayload({ config });
253
+ const result = await payload.find({
254
+ collection: collectionSlug,
255
+ draft,
256
+ limit: 1,
257
+ pagination: false,
258
+ overrideAccess: draft,
259
+ where: { [slugField]: { equals: slug } },
260
+ locale
261
+ });
262
+ return result.docs?.[0] ?? null;
645
263
  });
646
- const doc = result.docs?.[0] ?? null;
647
- console.log("[WWW] render/metadata:queryDocBySlug ->", doc ? "hit" : "miss");
648
- return doc;
649
- });
650
- var queryAllDocs = cache(async function queryAllDocs2({
651
- collectionSlug,
652
- slugField = "slug",
264
+ }
265
+ async function queryGlobal({
266
+ globalSlug,
653
267
  locale,
268
+ draft = false,
654
269
  config
655
270
  }) {
656
- console.log("[WWW] render/metadata:queryAllDocs collection=", collectionSlug, "locale=", locale);
657
- const payload = await getPayload({ config });
658
- const result = await payload.find({
659
- collection: collectionSlug,
660
- draft: false,
661
- limit: 1000,
662
- pagination: false,
663
- overrideAccess: false,
664
- select: { [slugField]: true },
665
- locale
271
+ return withUnstableCache([globalSlug, locale, draft], [createCollectionCacheKey({ globalSlug, locale })], async () => {
272
+ const payload = await getPayload({ config });
273
+ try {
274
+ return await payload.findGlobal({ slug: globalSlug, draft, locale });
275
+ } catch (error) {
276
+ console.warn("[WWW] queryGlobal failed", { globalSlug, locale, error: String(error) });
277
+ return null;
278
+ }
666
279
  });
667
- const docs = result.docs ?? [];
668
- console.log("[WWW] render/metadata:queryAllDocs -> count=", docs.length);
669
- return docs;
670
- });
671
- var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
280
+ }
281
+ async function queryAllDocs({
672
282
  collectionSlug,
673
- slug,
674
283
  slugField = "slug",
675
284
  locale,
676
285
  config
677
286
  }) {
678
- console.log("[WWW] render/metadata:queryAllLocaleSlugs collection=", collectionSlug, "slug=", slug, "locale=", locale);
679
- const payload = await getPayload({ config });
680
- const result = await payload.find({
681
- collection: collectionSlug,
682
- draft: false,
683
- limit: 1,
684
- pagination: false,
685
- overrideAccess: false,
686
- locale,
687
- where: { [slugField]: { equals: slug } },
688
- select: { [slugField]: true }
689
- });
690
- const doc = result.docs?.[0];
691
- if (!doc) {
692
- console.log("[WWW] render/metadata:queryAllLocaleSlugs -> undefined (no doc)");
693
- return;
694
- }
695
- let fieldValue = doc[slugField];
696
- if (doc.id != null) {
697
- const allLocales = await payload.findByID({
287
+ return withUnstableCache([collectionSlug, slugField, locale], [createCollectionCacheKey({ collectionSlug, slug: "__all__", locale })], async () => {
288
+ const payload = await getPayload({ config });
289
+ const result = await payload.find({
698
290
  collection: collectionSlug,
699
- id: doc.id,
700
- locale: "all",
701
291
  draft: false,
292
+ limit: 1000,
293
+ pagination: false,
702
294
  overrideAccess: false,
703
- select: { [slugField]: true }
704
- }).catch(() => null);
705
- if (allLocales)
706
- fieldValue = allLocales[slugField];
707
- }
708
- if (fieldValue && typeof fieldValue === "object") {
709
- console.log("[WWW] render/metadata:queryAllLocaleSlugs -> localized map=", JSON.stringify(fieldValue));
710
- return fieldValue;
711
- }
712
- const resolved = await config;
713
- const rawLocales = Array.isArray(resolved?.localization?.localeCodes) ? resolved.localization.localeCodes : resolved?.localization?.locales?.map((l) => l.code) ?? [];
714
- const out = {};
715
- for (const l of rawLocales)
716
- out[l] = String(fieldValue ?? slug);
717
- console.log("[WWW] render/metadata:queryAllLocaleSlugs -> flat-fanout locales=", rawLocales.length, "slug=", JSON.stringify(fieldValue ?? slug));
718
- return out;
719
- });
720
- var queryGlobal = cache(async function queryGlobal2({
721
- globalSlug,
722
- locale,
723
- depth = 0,
724
- draft = false,
295
+ select: { [slugField]: true },
296
+ locale
297
+ });
298
+ return result.docs ?? [];
299
+ });
300
+ }
301
+ async function queryAllLocaleSlugs({
302
+ collectionSlug,
303
+ id,
304
+ slugField = "slug",
725
305
  config
726
306
  }) {
727
- console.log("[WWW] render/metadata:queryGlobal global=", globalSlug, "locale=", locale, "depth=", depth, "draft=", draft);
728
307
  const payload = await getPayload({ config });
729
- try {
730
- const global = await payload.findGlobal({
731
- slug: globalSlug,
732
- depth,
733
- draft,
734
- locale
735
- });
736
- console.log("[WWW] render/metadata:queryGlobal -> hit");
737
- return global;
738
- } catch (error) {
739
- console.warn("[WWW] render/metadata:queryGlobal failed for slug=", globalSlug, "err=", String(error));
308
+ const doc = await payload.findByID({
309
+ collection: collectionSlug,
310
+ id,
311
+ locale: "all",
312
+ select: { [slugField]: true }
313
+ });
314
+ return doc?.[slugField];
315
+ }
316
+
317
+ // src/render/pages/createCollectionPageExports.tsx
318
+ import { setRequestLocale } from "next-intl/server";
319
+
320
+ // src/render/pages/utils/buildLocalizedPath.ts
321
+ function buildLocalizedPath(locale, prefix, slug, { routing }) {
322
+ return `${routing.localePrefix === "never" ? "" : routing.localePrefix === "always" ? locale : routing.localePrefix === "as-needed" ? locale === routing.defaultLocale ? "" : "/" + locale : (() => {
323
+ throw new Error("Unsupported locale prefix");
324
+ })()}${prefix ? "/" + prefix : ""}${slug ? "/" + slug : ""}`;
325
+ }
326
+ function buildLocalizedPaths(localesSlug, pagePathPrefix, { routing }) {
327
+ return routing.locales.reduce((paths, locale) => {
328
+ const slug = localesSlug[locale];
329
+ paths[locale] = buildLocalizedPath(locale, pagePathPrefix, slug, { routing });
330
+ return paths;
331
+ }, {});
332
+ }
333
+ function buildAlternates(locale, ...args) {
334
+ const siteUrl = args[2].siteUrl;
335
+ let localizedPaths = buildLocalizedPaths(...args);
336
+ localizedPaths["x-default"] = localizedPaths[args[2].routing.defaultLocale];
337
+ localizedPaths = Object.fromEntries(Object.entries(localizedPaths).map(([key, value]) => [key, siteUrl + localizedPaths[key]]));
338
+ return {
339
+ languages: localizedPaths,
340
+ canonical: localizedPaths[locale]
341
+ };
342
+ }
343
+
344
+ // src/render/pages/createCollectionPageExports.tsx
345
+ import { createSiteDefaults, generateMeta } from "@justanarthur/payload-plugin-seo/next-metadata";
346
+
347
+ // src/render/renderWWWModule.tsx
348
+ import { jsx as jsx5 } from "react/jsx-runtime";
349
+ async function renderWWWDataModule(data, {
350
+ collectionSlug,
351
+ configPath = "collections",
352
+ config: configPromise,
353
+ importMap
354
+ }, props) {
355
+ const config = await configPromise;
356
+ const renderPath = config[configPath]?.find((c) => c.slug === collectionSlug)?.custom?.[name]?.path;
357
+ const RenderModule = await getFromImportMap(renderPath, importMap);
358
+ if (!RenderModule) {
359
+ if (false) {}
740
360
  return null;
741
361
  }
742
- });
743
- function getRenderModuleExports(exportName, collection, importMap) {
744
- const path = collection?.custom?.path;
745
- if (!path) {
746
- console.log("[WWW] render/metadata:getRenderModuleExports no custom.path exportName=", exportName);
747
- return;
748
- }
749
- const mod = getFromImportMap(path, importMap);
750
- const value = mod?.[exportName];
751
- console.log("[WWW] render/metadata:getRenderModuleExports exportName=", exportName, "path=", path, "hit=", Boolean(value));
752
- return value;
362
+ return /* @__PURE__ */ jsx5(RenderModule, {
363
+ data,
364
+ config,
365
+ importMap,
366
+ ...props
367
+ });
753
368
  }
754
369
 
755
370
  // src/render/pages/createCollectionPageExports.tsx
756
- import { RichText } from "@payloadcms/richtext-lexical/react";
757
- import { jsx as jsx8, jsxs as jsxs5, Fragment as Fragment6 } from "react/jsx-runtime";
758
- var HOME_SLUG = "";
371
+ import { jsx as jsx6, Fragment as Fragment2 } from "react/jsx-runtime";
759
372
  function createCollectionPageExports({
760
- slug = "pages",
373
+ slug: collectionSlug = "pages",
761
374
  config: configPromise,
375
+ importMap,
762
376
  routing,
763
- importMap: importMapArg,
764
- renderPath,
765
- nested = false
766
- }, deps, options = {}) {
767
- const importMap = importMapArg ?? {};
768
- const { jsonLd: jsonLdOption = true, changefreq = "weekly", priority = 0.5, websiteName } = options;
769
- const {
770
- getServerSideURL,
771
- generateMeta,
772
- metadataType: metadataTypeOverride,
773
- showcase: showcaseOption,
774
- homeExtras
775
- } = deps;
776
- const showcaseEnabled = showcaseOption?.enabled === true;
777
- const { metadataHeading, jsonLdHeading } = showcaseOption ?? {};
778
- const locales = routing.locales;
779
- const defaultLocale = routing.defaultLocale;
780
- const metadataType = metadataTypeOverride ?? (slug === POSTS_SLUG ? "article" : "website");
781
- const defaultRenderPath = slug === POSTS_SLUG ? POSTS_RENDER_PATH : PAGES_RENDER_PATH;
782
- const localePrefixMode = typeof routing.localePrefix === "string" ? routing.localePrefix : routing.localePrefix?.mode ?? "always";
783
- const buildLocalePath = (locale, storedSlug) => {
784
- const urlPath = getUrlPath(storedSlugToSegments(storedSlug, nested), nested, HOME_SLUG);
785
- let result;
786
- if (localePrefixMode === "never")
787
- result = urlPath;
788
- else if (localePrefixMode === "as-needed" && locale === defaultLocale)
789
- result = urlPath;
790
- else
791
- result = `/${locale}${urlPath}`;
792
- console.log("[WWW] render/pages:createCollectionPageExports:buildLocalePath locale=", locale, "storedSlug=", storedSlug, "->", result);
793
- return result;
794
- };
795
- async function fetchDoc(locale, storedSlug, draft = false) {
796
- return queryDocBySlug({
797
- collectionSlug: slug,
798
- slug: storedSlug,
377
+ slugShape = "single"
378
+ }, {
379
+ getServerSideURL,
380
+ pagePathPrefix
381
+ }) {
382
+ const siteUrl = getServerSideURL();
383
+ async function fetchDoc(locale, slug) {
384
+ return queryDoc({
385
+ slug,
799
386
  locale,
800
- draft,
387
+ collectionSlug
388
+ }, {
801
389
  config: configPromise
802
390
  });
803
391
  }
804
- async function resolveHreflangAlternates(locale, storedSlug) {
805
- const siteUrl = getServerSideURL();
806
- const urlPath = buildLocalePath(locale, storedSlug);
807
- const canonical = `${siteUrl}${urlPath}`;
808
- const languages = await buildHreflangAlternates({
809
- siteUrl,
810
- locale,
811
- urlPrefix: "",
812
- storedSlug,
813
- nested,
814
- homeSlug: HOME_SLUG,
815
- defaultLocale,
816
- locales,
817
- localePrefix: localePrefixMode,
818
- queryAllLocaleSlugs: (s, l) => queryAllLocaleSlugs({ collectionSlug: slug, slug: s, slugField: "slug", locale: l, config: configPromise })
819
- });
820
- const alternates = {};
821
- for (const [key, url] of Object.entries(languages)) {
822
- alternates[key] = url;
823
- }
824
- console.log("[WWW] render/pages:createCollectionPageExports:resolveHreflangAlternates canonical=", canonical, "alts=", JSON.stringify(alternates));
825
- return { alternates, canonical };
826
- }
827
392
  const default_ = async (props) => {
828
- const { slug: rawSlugSegments, locale: incomingLocale } = await props.params ?? {};
829
- const slugSegments = Array.isArray(rawSlugSegments) ? rawSlugSegments : [];
830
- const locale = typeof incomingLocale === "string" ? incomingLocale : defaultLocale;
831
- console.log("[WWW] render/pages:createCollectionPageExports:default_ collectionSlug=", slug, "locale=", locale, "segments=", JSON.stringify(slugSegments), "showcase=", showcaseEnabled);
832
- if (!locales.includes(locale)) {
833
- console.error(`[WWW] render/pages:createCollectionPageExports:default_ notFound invalid-locale collection=${slug} locale=${locale} segments=${JSON.stringify(slugSegments)}`);
393
+ const params = await props.params;
394
+ const locale = params.locale;
395
+ if (!routing.locales.includes(locale)) {
834
396
  const { notFound } = await import("next/navigation");
835
- notFound();
836
- }
837
- const { setRequestLocale } = await import("next-intl/server");
838
- setRequestLocale(locale);
839
- const { draftMode } = await import("next/headers");
840
- const { isEnabled: draft } = await draftMode();
841
- console.log("[WWW] render/pages:createCollectionPageExports:default_ draftMode=", draft);
842
- const storedSlug = segmentsToStoredSlug(slugSegments, nested);
843
- const doc = await fetchDoc(locale, storedSlug, draft);
397
+ return notFound();
398
+ } else
399
+ setRequestLocale(locale);
400
+ const slug = paramsSlugToSlug(params.slug, slugShape);
401
+ const doc = await fetchDoc(locale, slug);
844
402
  if (!doc) {
845
- console.error(`[WWW] render/pages:createCollectionPageExports:default_ notFound no-doc collection=${slug} locale=${locale} storedSlug="${storedSlug}" segments=${JSON.stringify(slugSegments)} draft=${draft}`);
846
403
  const { notFound } = await import("next/navigation");
847
404
  notFound();
848
405
  }
849
- const cfg = await configPromise;
850
- const collectionCustomPath = cfg.collections.find((c) => c.slug === slug)?.custom?.path;
851
- const effectivePath = renderPath ?? collectionCustomPath ?? defaultRenderPath;
852
- console.log("[WWW] render/pages:createCollectionPageExports:default_ effectivePath=", effectivePath);
853
- const render = effectivePath === PAGES_RENDER_PATH ? /* @__PURE__ */ jsx8(PagesPage, {
854
- doc,
855
- importMap,
856
- config: cfg,
857
- locale
858
- }) : effectivePath === POSTS_RENDER_PATH ? doc ? await renderPostBody(doc, locale) : null : renderCollectionModule(cfg.collections, slug, importMap, {
859
- ...props,
860
- config: cfg,
861
- locale,
862
- searchParams: props.searchParams,
863
- doc
864
- });
865
- const jsonLdNodes = doc ? await generateJsonLd(slugSegments, doc, locale) : [];
866
- const { alternates: hreflangAlternates, canonical } = await resolveHreflangAlternates(locale, storedSlug);
867
- const inner = /* @__PURE__ */ jsxs5(Fragment6, {
868
- children: [
869
- jsonLdNodes.map(({ id, schema }) => /* @__PURE__ */ jsx8("script", {
870
- type: "application/ld+json",
871
- dangerouslySetInnerHTML: { __html: JSON.stringify(schema) }
872
- }, id)),
873
- render,
874
- draft ? (() => {
875
- const ResolvedListener = importMap?.[LIVE_PREVIEW_LISTENER_PATH];
876
- if (!ResolvedListener)
877
- return null;
878
- return /* @__PURE__ */ jsx8(Suspense, {
879
- fallback: null,
880
- children: /* @__PURE__ */ jsx8(ResolvedListener, {})
881
- });
882
- })() : null,
883
- storedSlug === HOME_SLUG && homeExtras ? await homeExtras({ locale, doc }) : null
884
- ]
885
- });
886
- if (!showcaseEnabled || !doc)
887
- return inner;
888
- const { PageShowcase: PageShowcase2 } = await Promise.resolve().then(() => (init_PageShowcase(), exports_PageShowcase));
889
- const { LocaleSwitcher: LocaleSwitcher2 } = await Promise.resolve().then(() => (init_LocaleSwitcher(), exports_LocaleSwitcher));
890
- const meta = await generateMeta({
891
- doc,
892
- url: canonical,
893
- type: metadataType,
894
- locale
895
- });
896
- return /* @__PURE__ */ jsx8(PageShowcase2, {
897
- metadata: meta,
898
- metadataHeading,
899
- jsonLdHeading,
900
- jsonLd: jsonLdNodes,
901
- localeSwitcher: /* @__PURE__ */ jsx8(LocaleSwitcher2, {
902
- currentLocale: locale,
903
- hreflangAlternates,
904
- labels: routing.labels
905
- }),
906
- children: inner
406
+ const rendered = renderWWWDataModule(doc, { collectionSlug, config: configPromise, importMap }, { ...props, locale });
407
+ return /* @__PURE__ */ jsx6(Fragment2, {
408
+ children: rendered
907
409
  });
908
410
  };
909
411
  async function generateMetadata(props) {
910
- const cfg = await configPromise;
911
- const { slug: rawSlugSegments, locale: incomingLocale } = await props.params ?? {};
912
- const slugSegments = Array.isArray(rawSlugSegments) ? rawSlugSegments : [];
913
- const locale = typeof incomingLocale === "string" ? incomingLocale : defaultLocale;
914
- console.log("[WWW] render/pages:createCollectionPageExports:generateMetadata collectionSlug=", slug, "locale=", locale, "segments=", JSON.stringify(slugSegments));
915
- if (!locales.includes(locale)) {
916
- console.log("[WWW] render/pages:createCollectionPageExports:generateMetadata invalid locale -> not found meta");
917
- return { title: "Not found", robots: { index: false, follow: false } };
918
- }
919
- const storedSlug = segmentsToStoredSlug(slugSegments, nested);
920
- const doc = await fetchDoc(locale, storedSlug);
921
- if (!doc) {
922
- console.log("[WWW] render/pages:createCollectionPageExports:generateMetadata no doc -> not found meta");
923
- return { title: "Not found", robots: { index: false, follow: false } };
924
- }
925
- const collection = cfg.collections.find((c) => c.slug === slug);
926
- if (!collection) {
927
- console.warn("[WWW] render/pages:createCollectionPageExports:generateMetadata collection not in config slug=", slug);
412
+ const params = await props.params;
413
+ const locale = params.locale, slug = paramsSlugToSlug(params.slug, slugShape);
414
+ const doc = await fetchDoc(locale, slug);
415
+ const [localesSlug, siteDefaults] = await Promise.all([
416
+ doc ? queryAllLocaleSlugs({
417
+ id: doc.id,
418
+ collectionSlug,
419
+ config: configPromise
420
+ }) : Promise.resolve({}),
421
+ createSiteDefaults({ config: configPromise, locale })
422
+ ]);
423
+ if (!doc)
928
424
  return {};
929
- }
930
- const { canonical, alternates } = await resolveHreflangAlternates(locale, storedSlug);
425
+ const alternates = buildAlternates(locale, localesSlug ?? {}, pagePathPrefix, { routing, siteUrl });
931
426
  const meta = await generateMeta({
932
- doc,
933
- url: canonical,
934
- type: metadataType,
935
- locale
427
+ meta: doc.meta,
428
+ url: alternates.canonical,
429
+ type: "website",
430
+ locale,
431
+ availableLocales: routing.locales,
432
+ fallback: doc,
433
+ siteDefaults
936
434
  });
937
- meta.alternates = {
938
- canonical,
939
- languages: Object.keys(alternates).length ? alternates : undefined
940
- };
941
- return meta;
435
+ console.log("[www#generateMetadata]", { alternates, meta, locale, localesSlug, doc });
436
+ return { ...meta, alternates };
942
437
  }
943
- async function generateJsonLd(slugSegments, doc, locale) {
944
- if (jsonLdOption === false || !doc)
945
- return [];
946
- const siteUrl = getServerSideURL();
947
- const storedSlug = segmentsToStoredSlug(slugSegments, nested);
948
- const urlPath = buildLocalePath(locale, storedSlug);
949
- const canonical = `${siteUrl}${urlPath}`;
950
- const entries = Array.isArray(jsonLdOption) ? jsonLdOption : metadataType === "article" ? [{ type: "article" }] : [{ type: "website" }];
951
- console.log("[WWW] render/pages:createCollectionPageExports:generateJsonLd collection=", slug, "locale=", locale, "entries=", entries.map((e) => e.type).join(","));
952
- const outputs = [];
953
- for (const entry of entries) {
954
- const id = entry.id ?? `jsonld-${entry.type}-${outputs.length}`;
955
- let schema = null;
956
- switch (entry.type) {
957
- case "article": {
958
- const articleOpts = {
959
- doc,
960
- url: canonical,
961
- locale,
962
- siteUrl,
963
- type: entry.schemaType ?? "BlogPosting"
964
- };
965
- if (entry.publisherName !== undefined)
966
- articleOpts.publisherName = entry.publisherName;
967
- if (entry.publisherLogo !== undefined)
968
- articleOpts.publisherLogo = entry.publisherLogo;
969
- schema = buildArticleLd(articleOpts);
970
- break;
971
- }
972
- case "website": {
973
- schema = {
974
- "@context": "https://schema.org",
975
- "@type": "WebSite",
976
- "@id": `${siteUrl}#website`,
977
- url: siteUrl,
978
- name: entry.name ?? websiteName ?? new URL(siteUrl).hostname,
979
- ...entry.alternateName ? { alternateName: entry.alternateName } : {},
980
- inLanguage: locale
981
- };
982
- break;
983
- }
984
- case "organization": {
985
- schema = buildOrganizationLd({
986
- siteUrl,
987
- name: entry.name,
988
- logo: entry.logo,
989
- sameAs: entry.sameAs
990
- });
991
- break;
992
- }
993
- case "breadcrumbs": {
994
- let items = entry.items ?? [];
995
- if (!items.length && entry.buildItems)
996
- items = entry.buildItems(doc, canonical);
997
- if (items.length > 0)
998
- schema = buildBreadcrumbsLd({ items, currentUrl: canonical });
999
- break;
1000
- }
1001
- case "custom": {
1002
- schema = entry.build({ doc, url: canonical, locale, siteUrl });
1003
- break;
1004
- }
1005
- }
1006
- if (schema)
1007
- outputs.push({ id, schema });
1008
- }
1009
- return outputs;
1010
- }
1011
- async function generateStaticParams() {
1012
- console.log("[WWW] render/pages:createCollectionPageExports:generateStaticParams collection=", slug, "locales=", JSON.stringify(locales));
1013
- const params = [];
1014
- for (const locale of locales) {
1015
- const docs = await queryAllDocs({ collectionSlug: slug, slugField: "slug", locale, config: configPromise });
1016
- for (const doc of docs) {
1017
- const slugVal = doc.slug;
1018
- if (typeof slugVal !== "string" || slugVal === "")
1019
- continue;
1020
- const segments = storedSlugToSegments(slugVal, nested);
1021
- params.push({ slug: Array.isArray(segments) ? segments : [segments], locale });
1022
- }
1023
- }
1024
- console.log("[WWW] render/pages:createCollectionPageExports:generateStaticParams -> count=", params.length);
1025
- return params;
438
+ async function generateStaticParams(props) {
439
+ const locale = (await props.params).locale;
440
+ const docs = await queryAllDocs({ locale, collectionSlug, config: configPromise });
441
+ return docs.filter((doc) => typeof doc.slug === "string" && doc.slug.length > 0).map((doc) => ({ slug: slugToParamsSlug(doc.slug, slugShape) }));
1026
442
  }
1027
443
  async function generateSitemap() {
1028
- console.log("[WWW] render/pages:createCollectionPageExports:generateSitemap collection=", slug, "locales=", JSON.stringify(locales));
444
+ const locale = routing.defaultLocale;
1029
445
  const docs = await queryAllDocs({
1030
- collectionSlug: slug,
1031
- slugField: "slug",
1032
- locale: defaultLocale,
446
+ collectionSlug,
447
+ locale,
1033
448
  config: configPromise
1034
449
  });
1035
- const siteUrl = getServerSideURL().replace(/\/$/, "");
1036
- const urls = [];
1037
- for (const doc of docs) {
1038
- const slugVal = doc.slug;
1039
- if (typeof slugVal !== "string" || slugVal === "")
1040
- continue;
1041
- for (const locale of locales) {
1042
- const urlPath = buildLocalePath(locale, slugVal);
1043
- const updatedAt = doc.updatedAt;
1044
- const lastmod = typeof updatedAt === "string" ? new Date(updatedAt).toISOString() : undefined;
1045
- urls.push({ url: `${siteUrl}${urlPath}`, lastModified: lastmod, changeFrequency: changefreq, priority });
1046
- }
1047
- }
1048
- console.log("[WWW] render/pages:createCollectionPageExports:generateSitemap -> urls=", urls.length);
1049
- return urls;
450
+ return await Promise.all(docs.map(async (doc) => {
451
+ const localesSlug = await queryAllLocaleSlugs({
452
+ id: doc.id,
453
+ collectionSlug,
454
+ config: configPromise
455
+ }) ?? {};
456
+ const alternates = buildAlternates(locale, localesSlug, pagePathPrefix, { routing, siteUrl });
457
+ return {
458
+ url: alternates.canonical,
459
+ alternates,
460
+ lastModified: doc.updatedAt || new Date
461
+ };
462
+ }));
1050
463
  }
464
+ generateSitemap.getServerSideURL = getServerSideURL;
465
+ generateSitemap.pagePathPrefix = pagePathPrefix;
1051
466
  return {
1052
467
  default: default_,
1053
468
  generateMetadata,
1054
469
  generateStaticParams,
1055
- generateSitemap,
1056
- generateJsonLd
470
+ generateSitemap
1057
471
  };
1058
472
  }
1059
- function addCollectionsToSitemap(exports) {
1060
- async function buildSitemap() {
1061
- const all = await Promise.all(exports.map((e) => e.generateSitemap()));
1062
- return all.flat();
1063
- }
1064
- return { default: buildSitemap, generateSitemap: buildSitemap };
1065
- }
1066
- async function renderPostBody(doc, locale) {
1067
- const typedDoc = doc;
1068
- const title = typedDoc.title ?? "";
1069
- const excerpt = typedDoc.excerpt ?? null;
1070
- const content = typedDoc.content;
1071
- return /* @__PURE__ */ jsxs5("article", {
1072
- className: "posts-page prose prose-neutral dark:prose-invert mx-auto max-w-3xl py-10",
1073
- children: [
1074
- /* @__PURE__ */ jsxs5("header", {
1075
- className: "posts-page__header not-prose mb-8",
1076
- children: [
1077
- /* @__PURE__ */ jsx8("h1", {
1078
- className: "posts-page__title text-4xl font-semibold tracking-tight",
1079
- children: title
1080
- }),
1081
- excerpt ? /* @__PURE__ */ jsx8("p", {
1082
- className: "posts-page__excerpt mt-3 text-lg text-muted-foreground",
1083
- children: excerpt
1084
- }) : null
1085
- ]
1086
- }),
1087
- content ? /* @__PURE__ */ jsx8("div", {
1088
- className: "posts-page__content",
1089
- children: /* @__PURE__ */ jsx8(RichText, {
1090
- data: content
1091
- })
1092
- }) : null
1093
- ]
1094
- });
473
+ function createSitemapFromCollections(...args) {
474
+ const baseUrl = args[0].getServerSideURL();
475
+ return function sitemap() {
476
+ const sitemaps = args.map((arg) => `${baseUrl}/${arg.pagePathPrefix}/sitemap.xml`);
477
+ const xml = `<?xml version="1.0" encoding="UTF-8"?>
478
+ <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
479
+ ${sitemaps.map((url) => ` <sitemap><loc>${url}</loc></sitemap>`).join(`
480
+ `)}
481
+ </sitemapindex>`;
482
+ return new Response(xml, {
483
+ headers: { "Content-Type": "application/xml" }
484
+ });
485
+ };
1095
486
  }
1096
487
 
1097
488
  // src/exports/pages.ts
1098
- var pages_default = {
1099
- createCollectionPageExports,
1100
- addCollectionsToSitemap,
1101
- PagesPage,
1102
- HeaderPage,
1103
- FooterPage
1104
- };
489
+ var pages = { createCollectionPageExports, PagesPage, HeaderPage, FooterPage };
490
+ var pages_default = pages;
1105
491
  export {
1106
492
  pages_default as default,
1107
493
  createCollectionPageExports,
1108
- addCollectionsToSitemap,
1109
494
  PagesPage,
1110
495
  HeaderPage,
1111
496
  FooterPage