@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
@@ -1,438 +1,276 @@
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 jsx4, jsxs } 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__ */ jsxs("div", {
57
- className: "page-showcase grid gap-8 lg:grid-cols-[1fr_320px]",
58
- children: [
59
- /* @__PURE__ */ jsx4("main", {
60
- className: "page-showcase__main",
61
- children
62
- }),
63
- /* @__PURE__ */ jsxs("aside", {
64
- className: "page-showcase__sidebar flex flex-col gap-6 text-sm",
65
- children: [
66
- /* @__PURE__ */ jsxs("section", {
67
- className: "page-showcase__locale",
68
- children: [
69
- /* @__PURE__ */ jsx4("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__ */ jsxs("section", {
77
- className: "page-showcase__metadata",
78
- children: [
79
- /* @__PURE__ */ jsx4("h2", {
80
- className: "m-0 mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",
81
- children: metadataHeading
82
- }),
83
- /* @__PURE__ */ jsx4("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__ */ jsxs(React.Fragment, {
86
- children: [
87
- /* @__PURE__ */ jsx4("dt", {
88
- className: "font-medium text-muted-foreground",
89
- children: label
90
- }),
91
- /* @__PURE__ */ jsx4("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__ */ jsxs("section", {
101
- className: "page-showcase__jsonld",
102
- children: [
103
- /* @__PURE__ */ jsx4("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__ */ jsxs("details", {
108
- className: "mb-2 rounded border border-border bg-muted/30 p-2",
109
- children: [
110
- /* @__PURE__ */ jsx4("summary", {
111
- className: "cursor-pointer font-mono text-xs",
112
- children: id
113
- }),
114
- /* @__PURE__ */ jsx4("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
2
 
139
- // src/render/components/LocaleSwitcher.tsx
140
- var exports_LocaleSwitcher = {};
141
- __export(exports_LocaleSwitcher, {
142
- LocaleSwitcher: () => LocaleSwitcher
143
- });
144
- import { jsx as jsx5, jsxs as jsxs2 } 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__ */ jsx5("nav", {
153
- "aria-label": "Language",
154
- className: "locale-switcher",
155
- children: /* @__PURE__ */ jsxs2("ul", {
156
- className: "flex flex-wrap gap-2 list-none p-0 m-0",
3
+ // src/render/pages/FooterPage.tsx
4
+ import"server-only";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ function FooterPage({ data }) {
7
+ const nav = data.nav ?? [];
8
+ const items = nav.filter((b) => b.blockType === "navItem");
9
+ const columns = nav.filter((b) => b.blockType === "navColumn");
10
+ const renderLink = (link, fallbackHref = "#") => {
11
+ if (!link)
12
+ return /* @__PURE__ */ jsx("a", {
13
+ href: fallbackHref,
14
+ children: link?.label ?? ""
15
+ });
16
+ if (link.type === "custom" && typeof link.url === "string") {
17
+ return /* @__PURE__ */ jsx("a", {
18
+ href: link.url,
19
+ children: link.label
20
+ });
21
+ }
22
+ if (link.type === "reference" && link.reference) {
23
+ const ref = link.reference;
24
+ if (typeof ref === "object" && ref.slug) {
25
+ return /* @__PURE__ */ jsx("a", {
26
+ href: `/${ref.slug}`,
27
+ children: link.label
28
+ });
29
+ }
30
+ }
31
+ return /* @__PURE__ */ jsx("a", {
32
+ href: fallbackHref,
33
+ children: link.label ?? ""
34
+ });
35
+ };
36
+ return /* @__PURE__ */ jsx("footer", {
37
+ children: /* @__PURE__ */ jsxs("div", {
157
38
  children: [
158
- locales.map((locale) => {
159
- const href = hreflangAlternates[locale];
160
- if (!href)
161
- return null;
162
- const isCurrent = locale === currentLocale;
163
- return /* @__PURE__ */ jsx5("li", {
164
- children: /* @__PURE__ */ jsx5("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()
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}`))
171
53
  })
172
- }, locale);
173
- }),
174
- hreflangAlternates["x-default"] ? /* @__PURE__ */ jsx5("li", {
175
- children: /* @__PURE__ */ jsx5("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
54
+ ]
55
+ }, `col-${i}`))
183
56
  ]
184
57
  })
185
58
  });
186
59
  }
187
- var init_LocaleSwitcher = () => {};
188
60
 
189
- // src/render/pages/createCollectionPageExports.tsx
61
+ // src/render/pages/HeaderPage.tsx
190
62
  import"server-only";
191
- import { Suspense } from "react";
192
-
193
- // src/config/constants.ts
194
- var PAGES_RENDER_PATH = "@justanarthur/payload-www/render-pages#PagesPage";
195
- var POSTS_RENDER_PATH = "@justanarthur/payload-www/render-pages#PostsPage";
196
- var HEADER_RENDER_PATH = "@justanarthur/payload-www/render-pages#HeaderPage";
197
- var FOOTER_RENDER_PATH = "@justanarthur/payload-www/render-pages#FooterPage";
198
- var LIVE_PREVIEW_LISTENER_PATH = "@justanarthur/payload-www/render-components#LivePreviewListener";
199
- var PAGES_SLUG = "pages";
200
- var POSTS_SLUG = "posts";
201
- var STATIC_PAGES_SLUG = "staticPages";
63
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
64
+ function HeaderPage({ data }) {
65
+ const nav = data.nav ?? [];
66
+ const items = nav.filter((b) => b.blockType === "navItem");
67
+ const columns = nav.filter((b) => b.blockType === "navColumn");
68
+ const renderLink = (link, fallbackHref = "#") => {
69
+ if (!link)
70
+ return /* @__PURE__ */ jsx2("a", {
71
+ href: fallbackHref,
72
+ children: link?.label ?? ""
73
+ });
74
+ if (link.type === "custom" && typeof link.url === "string") {
75
+ return /* @__PURE__ */ jsx2("a", {
76
+ href: link.url,
77
+ children: link.label
78
+ });
79
+ }
80
+ if (link.type === "reference" && link.reference) {
81
+ const ref = link.reference;
82
+ if (typeof ref === "object" && ref.slug) {
83
+ return /* @__PURE__ */ jsx2("a", {
84
+ href: `/${ref.slug}`,
85
+ children: link.label
86
+ });
87
+ }
88
+ }
89
+ return /* @__PURE__ */ jsx2("a", {
90
+ href: fallbackHref,
91
+ children: link.label ?? ""
92
+ });
93
+ };
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
+ ]
114
+ });
115
+ }
202
116
 
203
- // src/core/utils/getFromImportMap.ts
117
+ // src/render/getFromImportMap.ts
204
118
  function getFromImportMap(key, importMap) {
205
- return importMap[key.includes("#") ? key : key + "#default"];
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;
206
133
  }
207
134
 
208
- // src/render/utils/renderCollectionModule.tsx
209
- import { jsx } from "react/jsx-runtime";
210
- function renderCollectionModule(collection = [], slug, importMap, props) {
211
- const renderPath = collection?.find((c) => c.slug === slug)?.custom?.path;
212
- if (!renderPath) {
213
- console.log("[WWW] render/utils:renderCollectionModule no custom.path slug=", slug);
214
- return null;
215
- }
216
- const CollectionRenderModule = getFromImportMap(renderPath, importMap);
217
- if (!CollectionRenderModule) {
218
- console.error("[WWW] render/utils:renderCollectionModule not found slug=", slug, "path=", renderPath);
219
- if (false) {}
135
+ // package.json
136
+ var name = "@justanarthur/payload-www";
137
+
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)
220
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));
221
163
  }
222
- console.log("[WWW] render/utils:renderCollectionModule rendering slug=", slug, "path=", renderPath);
223
- return /* @__PURE__ */ jsx(CollectionRenderModule, {
224
- 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,
225
176
  ...props
226
177
  });
227
178
  }
228
179
 
229
- // src/render/metadata/hreflang.ts
230
- async function buildHreflangAlternates({
231
- siteUrl,
232
- locale,
233
- urlPrefix,
234
- storedSlug,
235
- queryAllLocaleSlugs,
236
- nested,
237
- homeSlug,
238
- defaultLocale,
239
- locales,
240
- localePrefix = "always"
241
- }) {
242
- const allLocaleSlugs = await queryAllLocaleSlugs(storedSlug, locale);
243
- console.log("[WWW] render/metadata:buildHreflangAlternates storedSlug=", storedSlug, "locale=", locale, "allLocaleSlugs=", JSON.stringify(allLocaleSlugs));
244
- const languages = {};
245
- const urlFor = (l, slug) => {
246
- const trimmedPrefix = urlPrefix.replace(/^\/|\/$/g, "");
247
- const prefixSegment = trimmedPrefix ? `/${trimmedPrefix}` : "";
248
- const urlPath = slug === homeSlug ? "/" : nested ? "/" + slug.replaceAll("_", "/") : "/" + slug;
249
- const localeSegment = localePrefix === "never" ? "" : localePrefix === "as-needed" && l === defaultLocale ? "" : `/${l}`;
250
- return `${siteUrl}${localeSegment}${prefixSegment}${urlPath}`;
251
- };
252
- for (const l of locales) {
253
- const slugForLocale = allLocaleSlugs?.[l];
254
- if (!slugForLocale)
255
- continue;
256
- languages[l] = urlFor(l, slugForLocale);
257
- }
258
- if (allLocaleSlugs?.[defaultLocale]) {
259
- languages["x-default"] = urlFor(defaultLocale, allLocaleSlugs[defaultLocale]);
260
- }
261
- console.log("[WWW] render/metadata:buildHreflangAlternates ->", JSON.stringify(languages));
262
- return languages;
180
+ // src/render/pages/PostsPage.tsx
181
+ import { RichText } from "@payloadcms/richtext-lexical/react";
182
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
183
+ async function PostsPage({ doc, locale, ...props }) {
184
+ return /* @__PURE__ */ jsxs3("article", {
185
+ className: "posts-page prose prose-neutral dark:prose-invert mx-auto max-w-3xl py-10",
186
+ children: [
187
+ /* @__PURE__ */ jsxs3("header", {
188
+ className: "posts-page__header not-prose mb-8",
189
+ children: [
190
+ /* @__PURE__ */ jsx5("h1", {
191
+ className: "posts-page__title text-4xl font-semibold tracking-tight",
192
+ children: doc.title
193
+ }),
194
+ doc.excerpt && /* @__PURE__ */ jsx5("p", {
195
+ className: "posts-page__excerpt mt-3 text-lg text-muted-foreground",
196
+ children: doc.excerpt
197
+ })
198
+ ]
199
+ }),
200
+ doc.content && /* @__PURE__ */ jsx5("div", {
201
+ className: "posts-page__content",
202
+ children: /* @__PURE__ */ jsx5(RichText, {
203
+ data: doc.content
204
+ })
205
+ })
206
+ ]
207
+ });
263
208
  }
264
209
 
265
- // src/render/metadata/jsonld.ts
266
- function getImageUrl(doc, siteUrl) {
267
- const img = doc?.meta?.image ?? doc?.heroImage ?? doc?.image;
268
- if (!img)
269
- return null;
270
- if (typeof img === "string")
271
- return img;
272
- if (img?.url)
273
- return img.url.startsWith("http") ? img.url : `${siteUrl}${img.url}`;
274
- return null;
275
- }
276
- function getImageUrlWithLog(doc, siteUrl) {
277
- const result = getImageUrl(doc, siteUrl);
278
- console.log("[WWW] render/metadata:jsonld:getImageUrl ->", result);
279
- return result;
280
- }
281
- function resolveLocalizedField(value, locale) {
282
- if (value == null)
283
- return "";
284
- if (typeof value === "string") {
285
- if (!value.startsWith("{"))
286
- return value;
287
- try {
288
- const parsed = JSON.parse(value);
289
- return resolveLocalizedField(parsed, locale);
290
- } catch {
291
- return value;
292
- }
293
- }
294
- if (typeof value !== "object")
295
- return "";
296
- const obj = value;
297
- if (typeof obj[locale] === "string" && obj[locale].length > 0) {
298
- return obj[locale];
299
- }
300
- return Object.values(obj).filter((v) => typeof v === "string" && v.length > 0).join(" / ");
301
- }
302
- function resolveLocalizedFieldWithLog(value, locale) {
303
- const result = resolveLocalizedField(value, locale);
304
- if (value && typeof value === "object") {
305
- console.log("[WWW] render/metadata:jsonld:resolveLocalizedField locale=", locale, "->", JSON.stringify(result));
306
- }
307
- return result;
308
- }
309
- function buildArticleLd({
310
- doc,
311
- url,
312
- locale,
313
- siteUrl,
314
- type = "BlogPosting",
315
- publisherName,
316
- publisherLogo
317
- }) {
318
- const name = publisherName ?? new URL(siteUrl).hostname;
319
- console.log("[WWW] render/metadata:buildArticleLd url=", url, "locale=", locale, "type=", type, "publisherName=", name);
320
- const ld = {
321
- "@context": "https://schema.org",
322
- "@type": type,
323
- "@id": `${url}#article`,
324
- headline: resolveLocalizedFieldWithLog(doc.title, locale),
325
- description: resolveLocalizedFieldWithLog(doc.meta?.description ?? doc.description ?? doc.excerpt, locale),
326
- inLanguage: locale,
327
- url,
328
- dateModified: doc.updatedAt ? new Date(doc.updatedAt).toISOString() : undefined
329
- };
330
- const datePublished = doc.publishedAt ?? doc.createdAt;
331
- if (datePublished)
332
- ld.datePublished = new Date(datePublished).toISOString();
333
- const imgUrl = getImageUrlWithLog(doc, siteUrl);
334
- if (imgUrl)
335
- ld.image = imgUrl;
336
- ld.author = { "@type": "Organization", name, url: siteUrl };
337
- const publisher = { "@type": "Organization", name };
338
- if (publisherLogo !== undefined) {
339
- if (publisherLogo !== null)
340
- publisher.logo = { "@type": "ImageObject", url: publisherLogo };
341
- }
342
- ld.publisher = publisher;
343
- return ld;
344
- }
345
- function buildBreadcrumbsLd({
346
- items,
347
- currentUrl
348
- }) {
349
- console.log("[WWW] render/metadata:buildBreadcrumbsLd items=", items.length, "currentUrl=", currentUrl);
350
- return {
351
- "@context": "https://schema.org",
352
- "@type": "BreadcrumbList",
353
- itemListElement: items.map((item, index) => ({
354
- "@type": "ListItem",
355
- position: index + 1,
356
- name: item.label,
357
- item: index === items.length - 1 ? currentUrl : item.url
358
- }))
359
- };
360
- }
361
- function buildOrganizationLd({
362
- siteUrl,
363
- name,
364
- logo,
365
- sameAs
366
- }) {
367
- console.log("[WWW] render/metadata:buildOrganizationLd siteUrl=", siteUrl, "name=", name, "logo?", Boolean(logo), "sameAs?", Boolean(sameAs));
368
- const org = {
369
- "@context": "https://schema.org",
370
- "@type": "Organization",
371
- "@id": `${siteUrl}#organization`,
372
- url: siteUrl,
373
- ...name && { name },
374
- ...logo && { logo: { "@type": "ImageObject", url: logo } },
375
- ...sameAs && sameAs.length > 0 && { sameAs }
376
- };
377
- return org;
378
- }
210
+ // src/render/pages/createCollectionPageExports.tsx
211
+ import"server-only";
379
212
 
380
213
  // src/render/metadata/slug.ts
381
214
  var SLUG_NESTED_DIVIDER = "_";
382
- function segmentsToStoredSlug(segments, nested) {
383
- if (!Array.isArray(segments)) {
384
- console.log("[WWW] render/metadata:segmentsToStoredSlug string passthrough:", JSON.stringify(segments));
385
- return segments;
386
- }
387
- const result = nested ? segments.join(SLUG_NESTED_DIVIDER) : segments[0] ?? "";
388
- console.log("[WWW] render/metadata:segmentsToStoredSlug nested=", nested, "segments=", JSON.stringify(segments), "->", result);
389
- return result;
390
- }
391
- function segmentsToUrlPath(segments, nested) {
392
- let result;
393
- if (!Array.isArray(segments))
394
- result = "/" + segments;
395
- else if (nested)
396
- result = "/" + segments.join("/");
397
- else
398
- result = "/" + (segments[0] ?? "");
399
- console.log("[WWW] render/metadata:segmentsToUrlPath nested=", nested, "segments=", JSON.stringify(segments), "->", result);
400
- return result;
215
+ function paramsSlugToSlug(slug, _shape) {
216
+ if (!slug)
217
+ return "";
218
+ return (Array.isArray(slug) ? slug : [slug]).join(SLUG_NESTED_DIVIDER);
401
219
  }
402
- function storedSlugToSegments(storedSlug, nested) {
403
- const result = nested ? storedSlug.split(SLUG_NESTED_DIVIDER) : storedSlug;
404
- console.log("[WWW] render/metadata:storedSlugToSegments nested=", nested, "storedSlug=", storedSlug, "->", JSON.stringify(result));
405
- return result;
220
+ function slugToParamsSlug(slug, shape) {
221
+ if (!slug)
222
+ return shape === "catch-all" ? [] : "";
223
+ return shape === "catch-all" ? slug.split(SLUG_NESTED_DIVIDER) : slug;
406
224
  }
407
- function buildCanonicalUrl({
408
- siteUrl,
409
- locale,
410
- urlPrefix,
411
- urlPath
412
- }) {
413
- const trimmedPrefix = urlPrefix.replace(/^\/|\/$/g, "");
414
- const prefixSegment = trimmedPrefix ? `/${trimmedPrefix}` : "";
415
- const result = `${siteUrl}/${locale}${prefixSegment}${urlPath}`;
416
- console.log("[WWW] render/metadata:buildCanonicalUrl siteUrl=", siteUrl, "locale=", locale, "urlPrefix=", urlPrefix, "urlPath=", urlPath, "->", result);
417
- return result;
225
+
226
+ // src/render/metadata/query.ts
227
+ import { getPayload } from "payload";
228
+
229
+ // src/collections/hooks/createRevalidateCollectionGlobalHook.ts
230
+ import { revalidateTag } from "next/cache";
231
+ function createRevalidateCollectionGlobalHook() {
232
+ const afterChangeDeleteHook = async ({ doc, req, ...args }) => {
233
+ const previousDoc = "previousDoc" in args ? args.previousDoc : null, locale = req.locale;
234
+ function revalidate(args2) {
235
+ try {
236
+ revalidateTag(createCollectionCacheKey({ ...args2, locale }), "max");
237
+ } catch (error) {
238
+ const msg = error instanceof Error ? error.message : String(error);
239
+ if (msg.includes("static generation store missing"))
240
+ return;
241
+ console.error(error);
242
+ }
243
+ }
244
+ if ("collection" in args) {
245
+ [
246
+ doc && doc._status !== "draft" && doc.slug,
247
+ previousDoc && previousDoc._status === "published" && previousDoc.slug
248
+ ].filter((slug) => slug !== undefined && slug !== false).map((slug) => revalidate({ collectionSlug: args.collection.slug, slug }));
249
+ } else {
250
+ revalidate({ globalSlug: args.global.slug });
251
+ }
252
+ return doc;
253
+ };
254
+ return { afterChange: afterChangeDeleteHook, afterDelete: afterChangeDeleteHook };
418
255
  }
419
- function getUrlPath(segments, nested, homeSlug) {
420
- const urlPath = segmentsToUrlPath(segments, nested);
421
- if (nested && !Array.isArray(segments)) {
422
- if (segments === homeSlug)
423
- return "/";
424
- } else if (nested && Array.isArray(segments)) {
425
- const stored = segments.join(SLUG_NESTED_DIVIDER);
426
- if (stored === homeSlug)
427
- return "/";
428
- }
429
- return urlPath;
256
+ function createCollectionCacheKey(args) {
257
+ return `${"globalSlug" in args ? args.globalSlug : args.collectionSlug + args.slug}_${args.locale}`;
430
258
  }
431
259
 
432
260
  // src/render/metadata/query.ts
433
- import { getPayload } from "payload";
434
- import { cache } from "react";
435
- var queryDocBySlug = cache(async function queryDocBySlug2({
261
+ async function withUnstableCache(keyParts, tags, fn) {
262
+ const { unstable_cache } = await import("next/cache");
263
+ return unstable_cache(fn, keyParts.map(String), { tags })();
264
+ }
265
+ async function queryDoc(args, { config: configPromise }) {
266
+ return withUnstableCache(Object.values(args), [createCollectionCacheKey(args)], async () => {
267
+ if ("globalSlug" in args)
268
+ return queryGlobal({ ...args, config: configPromise });
269
+ else
270
+ return queryDocBySlug({ ...args, config: configPromise });
271
+ });
272
+ }
273
+ async function queryDocBySlug({
436
274
  collectionSlug,
437
275
  slug,
438
276
  slugField = "slug",
@@ -440,625 +278,297 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
440
278
  draft = false,
441
279
  config
442
280
  }) {
443
- console.log("[WWW] render/metadata:queryDocBySlug collection=", collectionSlug, "slug=", slug, "slugField=", slugField, "locale=", locale, "draft=", draft);
444
- const payload = await getPayload({ config });
445
- const result = await payload.find({
446
- collection: collectionSlug,
447
- draft,
448
- limit: 1,
449
- pagination: false,
450
- overrideAccess: draft,
451
- where: { [slugField]: { equals: slug } },
452
- locale
281
+ return withUnstableCache([collectionSlug, slug, locale, draft], [createCollectionCacheKey({ collectionSlug, slug, locale })], async () => {
282
+ const payload = await getPayload({ config });
283
+ const result = await payload.find({
284
+ collection: collectionSlug,
285
+ draft,
286
+ limit: 1,
287
+ pagination: false,
288
+ overrideAccess: draft,
289
+ where: { [slugField]: { equals: slug } },
290
+ locale
291
+ });
292
+ return result.docs?.[0] ?? null;
453
293
  });
454
- const doc = result.docs?.[0] ?? null;
455
- console.log("[WWW] render/metadata:queryDocBySlug ->", doc ? "hit" : "miss");
456
- return doc;
457
- });
458
- var queryAllDocs = cache(async function queryAllDocs2({
459
- collectionSlug,
460
- slugField = "slug",
294
+ }
295
+ async function queryGlobal({
296
+ globalSlug,
461
297
  locale,
298
+ draft = false,
462
299
  config
463
300
  }) {
464
- console.log("[WWW] render/metadata:queryAllDocs collection=", collectionSlug, "locale=", locale);
465
- const payload = await getPayload({ config });
466
- const result = await payload.find({
467
- collection: collectionSlug,
468
- draft: false,
469
- limit: 1000,
470
- pagination: false,
471
- overrideAccess: false,
472
- select: { [slugField]: true },
473
- locale
301
+ return withUnstableCache([globalSlug, locale, draft], [createCollectionCacheKey({ globalSlug, locale })], async () => {
302
+ const payload = await getPayload({ config });
303
+ try {
304
+ return await payload.findGlobal({ slug: globalSlug, draft, locale });
305
+ } catch (error) {
306
+ console.warn("[WWW] queryGlobal failed", { globalSlug, locale, error: String(error) });
307
+ return null;
308
+ }
474
309
  });
475
- const docs = result.docs ?? [];
476
- console.log("[WWW] render/metadata:queryAllDocs -> count=", docs.length);
477
- return docs;
478
- });
479
- var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
310
+ }
311
+ async function queryAllDocs({
480
312
  collectionSlug,
481
- slug,
482
313
  slugField = "slug",
483
314
  locale,
484
315
  config
485
316
  }) {
486
- console.log("[WWW] render/metadata:queryAllLocaleSlugs collection=", collectionSlug, "slug=", slug, "locale=", locale);
487
- const payload = await getPayload({ config });
488
- const result = await payload.find({
489
- collection: collectionSlug,
490
- draft: false,
491
- limit: 1,
492
- pagination: false,
493
- overrideAccess: false,
494
- locale,
495
- where: { [slugField]: { equals: slug } },
496
- select: { [slugField]: true }
497
- });
498
- const doc = result.docs?.[0];
499
- if (!doc) {
500
- console.log("[WWW] render/metadata:queryAllLocaleSlugs -> undefined (no doc)");
501
- return;
502
- }
503
- let fieldValue = doc[slugField];
504
- if (doc.id != null) {
505
- const allLocales = await payload.findByID({
317
+ return withUnstableCache([collectionSlug, slugField, locale], [createCollectionCacheKey({ collectionSlug, slug: "__all__", locale })], async () => {
318
+ const payload = await getPayload({ config });
319
+ const result = await payload.find({
506
320
  collection: collectionSlug,
507
- id: doc.id,
508
- locale: "all",
509
321
  draft: false,
322
+ limit: 1000,
323
+ pagination: false,
510
324
  overrideAccess: false,
511
- select: { [slugField]: true }
512
- }).catch(() => null);
513
- if (allLocales)
514
- fieldValue = allLocales[slugField];
515
- }
516
- if (fieldValue && typeof fieldValue === "object") {
517
- console.log("[WWW] render/metadata:queryAllLocaleSlugs -> localized map=", JSON.stringify(fieldValue));
518
- return fieldValue;
519
- }
520
- const resolved = await config;
521
- const rawLocales = Array.isArray(resolved?.localization?.localeCodes) ? resolved.localization.localeCodes : resolved?.localization?.locales?.map((l) => l.code) ?? [];
522
- const out = {};
523
- for (const l of rawLocales)
524
- out[l] = String(fieldValue ?? slug);
525
- console.log("[WWW] render/metadata:queryAllLocaleSlugs -> flat-fanout locales=", rawLocales.length, "slug=", JSON.stringify(fieldValue ?? slug));
526
- return out;
527
- });
528
- var queryGlobal = cache(async function queryGlobal2({
529
- globalSlug,
530
- locale,
531
- depth = 0,
532
- draft = false,
325
+ select: { [slugField]: true },
326
+ locale
327
+ });
328
+ return result.docs ?? [];
329
+ });
330
+ }
331
+ async function queryAllLocaleSlugs({
332
+ collectionSlug,
333
+ id,
334
+ slugField = "slug",
533
335
  config
534
336
  }) {
535
- console.log("[WWW] render/metadata:queryGlobal global=", globalSlug, "locale=", locale, "depth=", depth, "draft=", draft);
536
337
  const payload = await getPayload({ config });
537
- try {
538
- const global = await payload.findGlobal({
539
- slug: globalSlug,
540
- depth,
541
- draft,
542
- locale
543
- });
544
- console.log("[WWW] render/metadata:queryGlobal -> hit");
545
- return global;
546
- } catch (error) {
547
- console.warn("[WWW] render/metadata:queryGlobal failed for slug=", globalSlug, "err=", String(error));
548
- return null;
549
- }
550
- });
551
- function getRenderModuleExports(exportName, collection, importMap) {
552
- const path = collection?.custom?.path;
553
- if (!path) {
554
- console.log("[WWW] render/metadata:getRenderModuleExports no custom.path exportName=", exportName);
555
- return;
556
- }
557
- const mod = getFromImportMap(path, importMap);
558
- const value = mod?.[exportName];
559
- console.log("[WWW] render/metadata:getRenderModuleExports exportName=", exportName, "path=", path, "hit=", Boolean(value));
560
- return value;
338
+ const doc = await payload.findByID({
339
+ collection: collectionSlug,
340
+ id,
341
+ locale: "all",
342
+ select: { [slugField]: true }
343
+ });
344
+ return doc?.[slugField];
561
345
  }
562
346
 
563
347
  // src/render/pages/createCollectionPageExports.tsx
564
- import { RichText } from "@payloadcms/richtext-lexical/react";
348
+ import { setRequestLocale } from "next-intl/server";
565
349
 
566
- // src/core/utils/generateImportName.ts
567
- function generateImportName(type, slug) {
568
- switch (type) {
569
- case "block":
570
- return `Block${slug.replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase())}#default`;
571
- case "page":
572
- return `Page${slug.replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase())}#default`;
573
- default:
574
- throw new Error(`Unknown type: ${type}`);
575
- }
350
+ // src/render/pages/utils/buildLocalizedPath.ts
351
+ function buildLocalizedPath(locale, prefix, slug, { routing }) {
352
+ return `${routing.localePrefix === "never" ? "" : routing.localePrefix === "always" ? locale : routing.localePrefix === "as-needed" ? locale === routing.defaultLocale ? "" : "/" + locale : (() => {
353
+ throw new Error("Unsupported locale prefix");
354
+ })()}${prefix ? "/" + prefix : ""}${slug ? "/" + slug : ""}`;
355
+ }
356
+ function buildLocalizedPaths(localesSlug, pagePathPrefix, { routing }) {
357
+ return routing.locales.reduce((paths, locale) => {
358
+ const slug = localesSlug[locale];
359
+ paths[locale] = buildLocalizedPath(locale, pagePathPrefix, slug, { routing });
360
+ return paths;
361
+ }, {});
362
+ }
363
+ function buildAlternates(locale, ...args) {
364
+ const siteUrl = args[2].siteUrl;
365
+ let localizedPaths = buildLocalizedPaths(...args);
366
+ localizedPaths["x-default"] = localizedPaths[args[2].routing.defaultLocale];
367
+ localizedPaths = Object.fromEntries(Object.entries(localizedPaths).map(([key, value]) => [key, siteUrl + localizedPaths[key]]));
368
+ return {
369
+ languages: localizedPaths,
370
+ canonical: localizedPaths[locale]
371
+ };
576
372
  }
577
373
 
578
- // src/render/blocks/renderBlocks.tsx
579
- import { jsx as jsx2, Fragment } from "react/jsx-runtime";
580
- var RenderBlocks = ({
581
- blocks,
582
- blockProps,
583
- config,
584
- importMap,
585
- locale,
586
- searchParams
587
- }) => {
588
- if (!blocks || !Array.isArray(blocks) || blocks.length === 0) {
589
- console.log("[WWW] render/blocks:RenderBlocks no blocks (locale=", locale, ")");
590
- return null;
591
- }
592
- console.log("[WWW] render/blocks:RenderBlocks rendering count=", blocks.length, "locale=", locale);
593
- const rendered = [];
594
- for (let i = 0;i < blocks.length; i++) {
595
- const block = blocks[i];
596
- const { blockType } = block;
597
- const importMapPath = config.admin?.dependencies?.[blockType]?.path ?? generateImportName("block", blockType);
598
- const Block = getFromImportMap(importMapPath, importMap);
599
- if (!Block) {
600
- console.warn(`[WWW] render/blocks:RenderBlocks no block for type=${blockType} importMapPath=${importMapPath} (locale=${locale})`);
601
- continue;
602
- }
603
- console.log("[WWW] render/blocks:RenderBlocks [", i, "] blockType=", blockType, "importMapPath=", importMapPath);
604
- rendered.push(/* @__PURE__ */ jsx2(Block, {
605
- index: i,
606
- ...blockProps,
607
- ...block,
608
- locale,
609
- searchParams
610
- }, i));
611
- }
612
- return /* @__PURE__ */ jsx2(Fragment, {
613
- children: rendered
614
- });
615
- };
374
+ // src/render/pages/createCollectionPageExports.tsx
375
+ import { createSiteDefaults, generateMeta } from "@justanarthur/payload-plugin-seo/next-metadata";
616
376
 
617
- // src/render/pages/PagesPage.tsx
618
- import { jsx as jsx3, Fragment as Fragment2 } from "react/jsx-runtime";
619
- async function PagesPage({ doc, ...props }) {
620
- if (!doc) {
621
- console.log("[WWW] render/pages:PagesPage no doc");
622
- return /* @__PURE__ */ jsx3(Fragment2, {});
377
+ // src/render/renderWWWModule.tsx
378
+ import { jsx as jsx6 } from "react/jsx-runtime";
379
+ async function renderWWWDataModule(data, {
380
+ collectionSlug,
381
+ configPath = "collections",
382
+ config: configPromise,
383
+ importMap
384
+ }, props) {
385
+ const config = await configPromise;
386
+ const renderPath = config[configPath]?.find((c) => c.slug === collectionSlug)?.custom?.[name]?.path;
387
+ const RenderModule = await getFromImportMap(renderPath, importMap);
388
+ if (!RenderModule) {
389
+ if (false) {}
390
+ return null;
623
391
  }
624
- const blocks = doc.blocks ?? [];
625
- console.log("[WWW] render/pages:PagesPage blocks=", blocks.length, "locale=", props.locale);
626
- return /* @__PURE__ */ jsx3(Fragment2, {
627
- children: /* @__PURE__ */ jsx3(RenderBlocks, {
628
- blocks,
629
- ...props
630
- })
392
+ return /* @__PURE__ */ jsx6(RenderModule, {
393
+ data,
394
+ config,
395
+ importMap,
396
+ ...props
631
397
  });
632
398
  }
633
399
 
634
400
  // src/render/pages/createCollectionPageExports.tsx
635
- import { jsx as jsx6, jsxs as jsxs3, Fragment as Fragment4 } from "react/jsx-runtime";
636
- var HOME_SLUG = "";
401
+ import { jsx as jsx7, Fragment as Fragment2 } from "react/jsx-runtime";
637
402
  function createCollectionPageExports({
638
- slug = "pages",
403
+ slug: collectionSlug = "pages",
639
404
  config: configPromise,
405
+ importMap,
640
406
  routing,
641
- importMap: importMapArg,
642
- renderPath,
643
- nested = false
644
- }, deps, options = {}) {
645
- const importMap = importMapArg ?? {};
646
- const { jsonLd: jsonLdOption = true, changefreq = "weekly", priority = 0.5, websiteName } = options;
647
- const {
648
- getServerSideURL,
649
- generateMeta,
650
- metadataType: metadataTypeOverride,
651
- showcase: showcaseOption,
652
- homeExtras
653
- } = deps;
654
- const showcaseEnabled = showcaseOption?.enabled === true;
655
- const { metadataHeading, jsonLdHeading } = showcaseOption ?? {};
656
- const locales = routing.locales;
657
- const defaultLocale = routing.defaultLocale;
658
- const metadataType = metadataTypeOverride ?? (slug === POSTS_SLUG ? "article" : "website");
659
- const defaultRenderPath = slug === POSTS_SLUG ? POSTS_RENDER_PATH : PAGES_RENDER_PATH;
660
- const localePrefixMode = typeof routing.localePrefix === "string" ? routing.localePrefix : routing.localePrefix?.mode ?? "always";
661
- const buildLocalePath = (locale, storedSlug) => {
662
- const urlPath = getUrlPath(storedSlugToSegments(storedSlug, nested), nested, HOME_SLUG);
663
- let result;
664
- if (localePrefixMode === "never")
665
- result = urlPath;
666
- else if (localePrefixMode === "as-needed" && locale === defaultLocale)
667
- result = urlPath;
668
- else
669
- result = `/${locale}${urlPath}`;
670
- console.log("[WWW] render/pages:createCollectionPageExports:buildLocalePath locale=", locale, "storedSlug=", storedSlug, "->", result);
671
- return result;
672
- };
673
- async function fetchDoc(locale, storedSlug, draft = false) {
674
- return queryDocBySlug({
675
- collectionSlug: slug,
676
- slug: storedSlug,
407
+ slugShape = "single"
408
+ }, {
409
+ getServerSideURL,
410
+ pagePathPrefix
411
+ }) {
412
+ const siteUrl = getServerSideURL();
413
+ async function fetchDoc(locale, slug) {
414
+ return queryDoc({
415
+ slug,
677
416
  locale,
678
- draft,
417
+ collectionSlug
418
+ }, {
679
419
  config: configPromise
680
420
  });
681
421
  }
682
- async function resolveHreflangAlternates(locale, storedSlug) {
683
- const siteUrl = getServerSideURL();
684
- const urlPath = buildLocalePath(locale, storedSlug);
685
- const canonical = `${siteUrl}${urlPath}`;
686
- const languages = await buildHreflangAlternates({
687
- siteUrl,
688
- locale,
689
- urlPrefix: "",
690
- storedSlug,
691
- nested,
692
- homeSlug: HOME_SLUG,
693
- defaultLocale,
694
- locales,
695
- localePrefix: localePrefixMode,
696
- queryAllLocaleSlugs: (s, l) => queryAllLocaleSlugs({ collectionSlug: slug, slug: s, slugField: "slug", locale: l, config: configPromise })
697
- });
698
- const alternates = {};
699
- for (const [key, url] of Object.entries(languages)) {
700
- alternates[key] = url;
701
- }
702
- console.log("[WWW] render/pages:createCollectionPageExports:resolveHreflangAlternates canonical=", canonical, "alts=", JSON.stringify(alternates));
703
- return { alternates, canonical };
704
- }
705
422
  const default_ = async (props) => {
706
- const { slug: rawSlugSegments, locale: incomingLocale } = await props.params ?? {};
707
- const slugSegments = Array.isArray(rawSlugSegments) ? rawSlugSegments : [];
708
- const locale = typeof incomingLocale === "string" ? incomingLocale : defaultLocale;
709
- console.log("[WWW] render/pages:createCollectionPageExports:default_ collectionSlug=", slug, "locale=", locale, "segments=", JSON.stringify(slugSegments), "showcase=", showcaseEnabled);
710
- if (!locales.includes(locale)) {
711
- console.error(`[WWW] render/pages:createCollectionPageExports:default_ notFound invalid-locale collection=${slug} locale=${locale} segments=${JSON.stringify(slugSegments)}`);
423
+ const params = await props.params;
424
+ const locale = params.locale;
425
+ if (!routing.locales.includes(locale)) {
712
426
  const { notFound } = await import("next/navigation");
713
- notFound();
714
- }
715
- const { setRequestLocale } = await import("next-intl/server");
716
- setRequestLocale(locale);
717
- const { draftMode } = await import("next/headers");
718
- const { isEnabled: draft } = await draftMode();
719
- console.log("[WWW] render/pages:createCollectionPageExports:default_ draftMode=", draft);
720
- const storedSlug = segmentsToStoredSlug(slugSegments, nested);
721
- const doc = await fetchDoc(locale, storedSlug, draft);
427
+ return notFound();
428
+ } else
429
+ setRequestLocale(locale);
430
+ const slug = paramsSlugToSlug(params.slug, slugShape);
431
+ const doc = await fetchDoc(locale, slug);
722
432
  if (!doc) {
723
- console.error(`[WWW] render/pages:createCollectionPageExports:default_ notFound no-doc collection=${slug} locale=${locale} storedSlug="${storedSlug}" segments=${JSON.stringify(slugSegments)} draft=${draft}`);
724
433
  const { notFound } = await import("next/navigation");
725
434
  notFound();
726
435
  }
727
- const cfg = await configPromise;
728
- const collectionCustomPath = cfg.collections.find((c) => c.slug === slug)?.custom?.path;
729
- const effectivePath = renderPath ?? collectionCustomPath ?? defaultRenderPath;
730
- console.log("[WWW] render/pages:createCollectionPageExports:default_ effectivePath=", effectivePath);
731
- const render = effectivePath === PAGES_RENDER_PATH ? /* @__PURE__ */ jsx6(PagesPage, {
732
- doc,
733
- importMap,
734
- config: cfg,
735
- locale
736
- }) : effectivePath === POSTS_RENDER_PATH ? doc ? await renderPostBody(doc, locale) : null : renderCollectionModule(cfg.collections, slug, importMap, {
737
- ...props,
738
- config: cfg,
739
- locale,
740
- searchParams: props.searchParams,
741
- doc
742
- });
743
- const jsonLdNodes = doc ? await generateJsonLd(slugSegments, doc, locale) : [];
744
- const { alternates: hreflangAlternates, canonical } = await resolveHreflangAlternates(locale, storedSlug);
745
- const inner = /* @__PURE__ */ jsxs3(Fragment4, {
746
- children: [
747
- jsonLdNodes.map(({ id, schema }) => /* @__PURE__ */ jsx6("script", {
748
- type: "application/ld+json",
749
- dangerouslySetInnerHTML: { __html: JSON.stringify(schema) }
750
- }, id)),
751
- render,
752
- draft ? (() => {
753
- const ResolvedListener = importMap?.[LIVE_PREVIEW_LISTENER_PATH];
754
- if (!ResolvedListener)
755
- return null;
756
- return /* @__PURE__ */ jsx6(Suspense, {
757
- fallback: null,
758
- children: /* @__PURE__ */ jsx6(ResolvedListener, {})
759
- });
760
- })() : null,
761
- storedSlug === HOME_SLUG && homeExtras ? await homeExtras({ locale, doc }) : null
762
- ]
763
- });
764
- if (!showcaseEnabled || !doc)
765
- return inner;
766
- const { PageShowcase: PageShowcase2 } = await Promise.resolve().then(() => (init_PageShowcase(), exports_PageShowcase));
767
- const { LocaleSwitcher: LocaleSwitcher2 } = await Promise.resolve().then(() => (init_LocaleSwitcher(), exports_LocaleSwitcher));
768
- const meta = await generateMeta({
769
- doc,
770
- url: canonical,
771
- type: metadataType,
772
- locale
773
- });
774
- return /* @__PURE__ */ jsx6(PageShowcase2, {
775
- metadata: meta,
776
- metadataHeading,
777
- jsonLdHeading,
778
- jsonLd: jsonLdNodes,
779
- localeSwitcher: /* @__PURE__ */ jsx6(LocaleSwitcher2, {
780
- currentLocale: locale,
781
- hreflangAlternates,
782
- labels: routing.labels
783
- }),
784
- children: inner
436
+ const rendered = renderWWWDataModule(doc, { collectionSlug, config: configPromise, importMap }, { ...props, locale });
437
+ return /* @__PURE__ */ jsx7(Fragment2, {
438
+ children: rendered
785
439
  });
786
440
  };
787
441
  async function generateMetadata(props) {
788
- const cfg = await configPromise;
789
- const { slug: rawSlugSegments, locale: incomingLocale } = await props.params ?? {};
790
- const slugSegments = Array.isArray(rawSlugSegments) ? rawSlugSegments : [];
791
- const locale = typeof incomingLocale === "string" ? incomingLocale : defaultLocale;
792
- console.log("[WWW] render/pages:createCollectionPageExports:generateMetadata collectionSlug=", slug, "locale=", locale, "segments=", JSON.stringify(slugSegments));
793
- if (!locales.includes(locale)) {
794
- console.log("[WWW] render/pages:createCollectionPageExports:generateMetadata invalid locale -> not found meta");
795
- return { title: "Not found", robots: { index: false, follow: false } };
796
- }
797
- const storedSlug = segmentsToStoredSlug(slugSegments, nested);
798
- const doc = await fetchDoc(locale, storedSlug);
799
- if (!doc) {
800
- console.log("[WWW] render/pages:createCollectionPageExports:generateMetadata no doc -> not found meta");
801
- return { title: "Not found", robots: { index: false, follow: false } };
802
- }
803
- const collection = cfg.collections.find((c) => c.slug === slug);
804
- if (!collection) {
805
- console.warn("[WWW] render/pages:createCollectionPageExports:generateMetadata collection not in config slug=", slug);
442
+ const params = await props.params;
443
+ const locale = params.locale, slug = paramsSlugToSlug(params.slug, slugShape);
444
+ const doc = await fetchDoc(locale, slug);
445
+ const [localesSlug, siteDefaults] = await Promise.all([
446
+ doc ? queryAllLocaleSlugs({
447
+ id: doc.id,
448
+ collectionSlug,
449
+ config: configPromise
450
+ }) : Promise.resolve({}),
451
+ createSiteDefaults({ config: configPromise, locale })
452
+ ]);
453
+ if (!doc)
806
454
  return {};
807
- }
808
- const { canonical, alternates } = await resolveHreflangAlternates(locale, storedSlug);
455
+ const alternates = buildAlternates(locale, localesSlug ?? {}, pagePathPrefix, { routing, siteUrl });
809
456
  const meta = await generateMeta({
810
- doc,
811
- url: canonical,
812
- type: metadataType,
813
- locale
457
+ meta: doc.meta,
458
+ url: alternates.canonical,
459
+ type: "website",
460
+ locale,
461
+ availableLocales: routing.locales,
462
+ fallback: doc,
463
+ siteDefaults
814
464
  });
815
- meta.alternates = {
816
- canonical,
817
- languages: Object.keys(alternates).length ? alternates : undefined
818
- };
819
- return meta;
465
+ console.log("[www#generateMetadata]", { alternates, meta, locale, localesSlug, doc });
466
+ return { ...meta, alternates };
820
467
  }
821
- async function generateJsonLd(slugSegments, doc, locale) {
822
- if (jsonLdOption === false || !doc)
823
- return [];
824
- const siteUrl = getServerSideURL();
825
- const storedSlug = segmentsToStoredSlug(slugSegments, nested);
826
- const urlPath = buildLocalePath(locale, storedSlug);
827
- const canonical = `${siteUrl}${urlPath}`;
828
- const entries = Array.isArray(jsonLdOption) ? jsonLdOption : metadataType === "article" ? [{ type: "article" }] : [{ type: "website" }];
829
- console.log("[WWW] render/pages:createCollectionPageExports:generateJsonLd collection=", slug, "locale=", locale, "entries=", entries.map((e) => e.type).join(","));
830
- const outputs = [];
831
- for (const entry of entries) {
832
- const id = entry.id ?? `jsonld-${entry.type}-${outputs.length}`;
833
- let schema = null;
834
- switch (entry.type) {
835
- case "article": {
836
- const articleOpts = {
837
- doc,
838
- url: canonical,
839
- locale,
840
- siteUrl,
841
- type: entry.schemaType ?? "BlogPosting"
842
- };
843
- if (entry.publisherName !== undefined)
844
- articleOpts.publisherName = entry.publisherName;
845
- if (entry.publisherLogo !== undefined)
846
- articleOpts.publisherLogo = entry.publisherLogo;
847
- schema = buildArticleLd(articleOpts);
848
- break;
849
- }
850
- case "website": {
851
- schema = {
852
- "@context": "https://schema.org",
853
- "@type": "WebSite",
854
- "@id": `${siteUrl}#website`,
855
- url: siteUrl,
856
- name: entry.name ?? websiteName ?? new URL(siteUrl).hostname,
857
- ...entry.alternateName ? { alternateName: entry.alternateName } : {},
858
- inLanguage: locale
859
- };
860
- break;
861
- }
862
- case "organization": {
863
- schema = buildOrganizationLd({
864
- siteUrl,
865
- name: entry.name,
866
- logo: entry.logo,
867
- sameAs: entry.sameAs
868
- });
869
- break;
870
- }
871
- case "breadcrumbs": {
872
- let items = entry.items ?? [];
873
- if (!items.length && entry.buildItems)
874
- items = entry.buildItems(doc, canonical);
875
- if (items.length > 0)
876
- schema = buildBreadcrumbsLd({ items, currentUrl: canonical });
877
- break;
878
- }
879
- case "custom": {
880
- schema = entry.build({ doc, url: canonical, locale, siteUrl });
881
- break;
882
- }
883
- }
884
- if (schema)
885
- outputs.push({ id, schema });
886
- }
887
- return outputs;
888
- }
889
- async function generateStaticParams() {
890
- console.log("[WWW] render/pages:createCollectionPageExports:generateStaticParams collection=", slug, "locales=", JSON.stringify(locales));
891
- const params = [];
892
- for (const locale of locales) {
893
- const docs = await queryAllDocs({ collectionSlug: slug, slugField: "slug", locale, config: configPromise });
894
- for (const doc of docs) {
895
- const slugVal = doc.slug;
896
- if (typeof slugVal !== "string" || slugVal === "")
897
- continue;
898
- const segments = storedSlugToSegments(slugVal, nested);
899
- params.push({ slug: Array.isArray(segments) ? segments : [segments], locale });
900
- }
901
- }
902
- console.log("[WWW] render/pages:createCollectionPageExports:generateStaticParams -> count=", params.length);
903
- return params;
468
+ async function generateStaticParams(props) {
469
+ const locale = (await props.params).locale;
470
+ const docs = await queryAllDocs({ locale, collectionSlug, config: configPromise });
471
+ return docs.filter((doc) => typeof doc.slug === "string" && doc.slug.length > 0).map((doc) => ({ slug: slugToParamsSlug(doc.slug, slugShape) }));
904
472
  }
905
473
  async function generateSitemap() {
906
- console.log("[WWW] render/pages:createCollectionPageExports:generateSitemap collection=", slug, "locales=", JSON.stringify(locales));
474
+ const locale = routing.defaultLocale;
907
475
  const docs = await queryAllDocs({
908
- collectionSlug: slug,
909
- slugField: "slug",
910
- locale: defaultLocale,
476
+ collectionSlug,
477
+ locale,
911
478
  config: configPromise
912
479
  });
913
- const siteUrl = getServerSideURL().replace(/\/$/, "");
914
- const urls = [];
915
- for (const doc of docs) {
916
- const slugVal = doc.slug;
917
- if (typeof slugVal !== "string" || slugVal === "")
918
- continue;
919
- for (const locale of locales) {
920
- const urlPath = buildLocalePath(locale, slugVal);
921
- const updatedAt = doc.updatedAt;
922
- const lastmod = typeof updatedAt === "string" ? new Date(updatedAt).toISOString() : undefined;
923
- urls.push({ url: `${siteUrl}${urlPath}`, lastModified: lastmod, changeFrequency: changefreq, priority });
924
- }
925
- }
926
- console.log("[WWW] render/pages:createCollectionPageExports:generateSitemap -> urls=", urls.length);
927
- return urls;
928
- }
480
+ return await Promise.all(docs.map(async (doc) => {
481
+ const localesSlug = await queryAllLocaleSlugs({
482
+ id: doc.id,
483
+ collectionSlug,
484
+ config: configPromise
485
+ }) ?? {};
486
+ const alternates = buildAlternates(locale, localesSlug, pagePathPrefix, { routing, siteUrl });
487
+ return {
488
+ url: alternates.canonical,
489
+ alternates,
490
+ lastModified: doc.updatedAt || new Date
491
+ };
492
+ }));
493
+ }
494
+ generateSitemap.getServerSideURL = getServerSideURL;
495
+ generateSitemap.pagePathPrefix = pagePathPrefix;
929
496
  return {
930
497
  default: default_,
931
498
  generateMetadata,
932
499
  generateStaticParams,
933
- generateSitemap,
934
- generateJsonLd
500
+ generateSitemap
935
501
  };
936
502
  }
937
- function addCollectionsToSitemap(exports) {
938
- async function buildSitemap() {
939
- const all = await Promise.all(exports.map((e) => e.generateSitemap()));
940
- return all.flat();
941
- }
942
- return { default: buildSitemap, generateSitemap: buildSitemap };
943
- }
944
- async function renderPostBody(doc, locale) {
945
- const typedDoc = doc;
946
- const title = typedDoc.title ?? "";
947
- const excerpt = typedDoc.excerpt ?? null;
948
- const content = typedDoc.content;
949
- return /* @__PURE__ */ jsxs3("article", {
950
- className: "posts-page prose prose-neutral dark:prose-invert mx-auto max-w-3xl py-10",
951
- children: [
952
- /* @__PURE__ */ jsxs3("header", {
953
- className: "posts-page__header not-prose mb-8",
954
- children: [
955
- /* @__PURE__ */ jsx6("h1", {
956
- className: "posts-page__title text-4xl font-semibold tracking-tight",
957
- children: title
958
- }),
959
- excerpt ? /* @__PURE__ */ jsx6("p", {
960
- className: "posts-page__excerpt mt-3 text-lg text-muted-foreground",
961
- children: excerpt
962
- }) : null
963
- ]
964
- }),
965
- content ? /* @__PURE__ */ jsx6("div", {
966
- className: "posts-page__content",
967
- children: /* @__PURE__ */ jsx6(RichText, {
968
- data: content
969
- })
970
- }) : null
971
- ]
972
- });
503
+ function createSitemapFromCollections(...args) {
504
+ const baseUrl = args[0].getServerSideURL();
505
+ return function sitemap() {
506
+ const sitemaps = args.map((arg) => `${baseUrl}/${arg.pagePathPrefix}/sitemap.xml`);
507
+ const xml = `<?xml version="1.0" encoding="UTF-8"?>
508
+ <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
509
+ ${sitemaps.map((url) => ` <sitemap><loc>${url}</loc></sitemap>`).join(`
510
+ `)}
511
+ </sitemapindex>`;
512
+ return new Response(xml, {
513
+ headers: { "Content-Type": "application/xml" }
514
+ });
515
+ };
973
516
  }
974
517
 
975
518
  // src/render/pages/createRootLayoutExports.tsx
976
519
  import"server-only";
977
-
978
- // src/render/utils/renderGlobalModule.tsx
979
- import { jsx as jsx7 } from "react/jsx-runtime";
980
- function renderGlobalModule(globals = [], slug, importMap, props) {
981
- const renderPath = globals?.find((g) => g.slug === slug)?.custom?.path;
982
- if (!renderPath) {
983
- console.log("[WWW] render/utils:renderGlobalModule no custom.path slug=", slug);
984
- return null;
985
- }
986
- const GlobalRenderModule = getFromImportMap(renderPath, importMap);
987
- if (!GlobalRenderModule) {
988
- console.error("[WWW] render/utils:renderGlobalModule not found slug=", slug, "path=", renderPath);
989
- if (false) {}
990
- return null;
991
- }
992
- console.log("[WWW] render/utils:renderGlobalModule rendering slug=", slug, "path=", renderPath);
993
- return /* @__PURE__ */ jsx7(GlobalRenderModule, {
994
- importMap,
995
- ...props
996
- });
997
- }
998
-
999
- // src/render/pages/createRootLayoutExports.tsx
1000
- import { jsx as jsx8, jsxs as jsxs4, Fragment as Fragment5 } from "react/jsx-runtime";
1001
- function createRootLayoutExports(args) {
1002
- const { config: configPromise, routing, importMap = {}, providers, head, htmlAttrs } = args;
1003
- async function RootLayout({
1004
- children,
1005
- params
1006
- }) {
1007
- const { locale } = await params;
1008
- console.log("[WWW] render/pages:createRootLayoutExports:RootLayout locale=", locale);
520
+ import { setRequestLocale as setRequestLocale2 } from "next-intl/server";
521
+ import { NextIntlClientProvider } from "next-intl";
522
+ import { RootJsonLd } from "@justanarthur/payload-plugin-seo/root-jsonld";
523
+ import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
524
+ function createRootLayoutExports({
525
+ config: configPromise,
526
+ importMap,
527
+ routing
528
+ }, {
529
+ providers,
530
+ htmlAttrs,
531
+ getServerSideURL
532
+ } = {}) {
533
+ async function RootLayout(props) {
534
+ const params = await props.params;
535
+ const locale = params.locale;
1009
536
  if (!routing.locales.includes(locale)) {
1010
- console.error("[WWW] render/pages:createRootLayoutExports:RootLayout invalid locale=", locale);
1011
537
  const { notFound } = await import("next/navigation");
1012
- notFound();
1013
- }
1014
- const { setRequestLocale, getMessages } = await import("next-intl/server");
1015
- setRequestLocale(locale);
1016
- const messages = await getMessages();
1017
- const { draftMode: nextDraftMode } = await import("next/headers");
1018
- const { isEnabled: draftMode } = await nextDraftMode();
1019
- console.log("[WWW] render/pages:createRootLayoutExports:RootLayout draftMode=", draftMode);
1020
- const cfg = await configPromise;
1021
- const [headerData, footerData] = await Promise.all([
1022
- queryGlobal({ globalSlug: "header", locale, depth: 0, config: configPromise }),
1023
- queryGlobal({ globalSlug: "footer", locale, depth: 0, config: configPromise })
538
+ return notFound();
539
+ } else
540
+ setRequestLocale2(locale);
541
+ const [
542
+ header,
543
+ footer
544
+ ] = await Promise.all([
545
+ queryDoc({ globalSlug: "header", locale }, { config: configPromise }),
546
+ queryDoc({ globalSlug: "footer", locale }, { config: configPromise })
1024
547
  ]);
1025
- console.log("[WWW] render/pages:createRootLayoutExports:RootLayout header?", Boolean(headerData), "footer?", Boolean(footerData));
1026
- const headerEl = renderGlobalModule(cfg.globals, "header", importMap, {
1027
- data: headerData,
1028
- locale
1029
- });
1030
- const footerEl = renderGlobalModule(cfg.globals, "footer", importMap, {
1031
- data: footerData,
1032
- locale
1033
- });
1034
- const htmlAttributeOverrides = htmlAttrs?.(locale) ?? {};
548
+ const renderedHeader = renderWWWDataModule(header, { collectionSlug: "header", configPath: "globals", config: configPromise, importMap }, { ...props, locale }), renderedFooter = renderWWWDataModule(footer, { collectionSlug: "footer", configPath: "globals", config: configPromise, importMap }, { ...props, locale });
1035
549
  const mergedHtmlAttrs = {
1036
550
  lang: locale,
1037
551
  suppressHydrationWarning: true,
1038
- ...htmlAttributeOverrides
552
+ ...htmlAttrs?.(locale) ?? {}
1039
553
  };
1040
- const providersArgs = {
1041
- children: /* @__PURE__ */ jsxs4(Fragment5, {
1042
- children: [
1043
- headerEl,
1044
- children,
1045
- footerEl
1046
- ]
1047
- }),
554
+ const rootJsonLd = getServerSideURL ? /* @__PURE__ */ jsx8(RootJsonLd, {
555
+ config: configPromise,
1048
556
  locale,
1049
- messages,
1050
- draftMode
1051
- };
1052
- return /* @__PURE__ */ jsxs4("html", {
557
+ getServerSideURL,
558
+ locales: routing.locales
559
+ }) : null;
560
+ return /* @__PURE__ */ jsx8("html", {
1053
561
  ...mergedHtmlAttrs,
1054
- children: [
1055
- /* @__PURE__ */ jsx8("head", {
1056
- children: head?.()
1057
- }),
1058
- /* @__PURE__ */ jsx8("body", {
1059
- children: providers ? providers(providersArgs) : children
562
+ children: /* @__PURE__ */ jsx8("body", {
563
+ children: /* @__PURE__ */ jsxs4(NextIntlClientProvider, {
564
+ children: [
565
+ rootJsonLd,
566
+ renderedHeader,
567
+ providers ? providers({ children: props.children, locale }) : props.children,
568
+ renderedFooter
569
+ ]
1060
570
  })
1061
- ]
571
+ })
1062
572
  });
1063
573
  }
1064
574
  return {
@@ -1067,540 +577,17 @@ function createRootLayoutExports(args) {
1067
577
  };
1068
578
  }
1069
579
 
1070
- // src/render/pages/createStaticPageExports.tsx
1071
- import"server-only";
1072
-
1073
- // src/core/access/index.ts
1074
- var anyone = () => true;
1075
- var authenticated = ({ req: { user } }) => Boolean(user);
1076
- var authenticatedOrPublished = ({ req: { user } }) => {
1077
- if (user)
1078
- return true;
1079
- return { _status: { equals: "published" } };
1080
- };
1081
-
1082
- // src/render/_locale.ts
1083
- function prefixFor(locale, defaultLocale, mode) {
1084
- let result;
1085
- if (mode === "never")
1086
- result = "";
1087
- else if (mode === "as-needed" && locale === defaultLocale)
1088
- result = "";
1089
- else
1090
- result = `/${locale}`;
1091
- console.log("[WWW] render/_locale:prefixFor locale=", locale, "default=", defaultLocale, "mode=", mode, "->", JSON.stringify(result));
1092
- return result;
1093
- }
1094
- function resolveLocale(req) {
1095
- if (!req || typeof req !== "object") {
1096
- console.log('[WWW] render/_locale:resolveLocale -> "" (no req)');
1097
- return "";
1098
- }
1099
- const r = req;
1100
- if (typeof r.locale === "string" && r.locale.length > 0) {
1101
- console.log("[WWW] render/_locale:resolveLocale ->", r.locale, "(from req.locale)");
1102
- return r.locale;
1103
- }
1104
- const fallback = r.payload?.config?.localization?.defaultLocale;
1105
- if (typeof fallback === "string" && fallback.length > 0) {
1106
- console.log("[WWW] render/_locale:resolveLocale ->", fallback, "(from config.localization.defaultLocale)");
1107
- return fallback;
1108
- }
1109
- console.log('[WWW] render/_locale:resolveLocale -> "" (no locale anywhere)');
1110
- return "";
1111
- }
1112
- function allLocales(req) {
1113
- if (!req || typeof req !== "object") {
1114
- console.log("[WWW] render/_locale:allLocales -> [] (no req)");
1115
- return [];
1116
- }
1117
- const r = req;
1118
- const list = r.payload?.config?.localization?.locales;
1119
- if (!Array.isArray(list) || list.length === 0) {
1120
- console.log("[WWW] render/_locale:allLocales -> [] (no locales declared)");
1121
- return [];
1122
- }
1123
- const out = [];
1124
- for (const entry of list) {
1125
- if (typeof entry === "string" && entry.length > 0) {
1126
- out.push(entry);
1127
- } else if (entry && typeof entry === "object" && "code" in entry) {
1128
- const code = entry.code;
1129
- if (typeof code === "string" && code.length > 0)
1130
- out.push(code);
1131
- }
1132
- }
1133
- console.log("[WWW] render/_locale:allLocales ->", JSON.stringify(out));
1134
- return out;
1135
- }
1136
-
1137
- // src/render/hooks/_shared.ts
1138
- var cachePromise = null;
1139
- function nextCacheImport() {
1140
- return cachePromise ??= import("next/cache");
1141
- }
1142
- function shouldSkipRevalidate(context) {
1143
- const skip = Boolean(context?.disableRevalidate);
1144
- if (skip)
1145
- console.log("[WWW] render/hooks:_shared:shouldSkipRevalidate -> skip");
1146
- return skip;
1147
- }
1148
- async function safeRevalidatePath(payload, path) {
1149
- console.log("[WWW] render/hooks:_shared:safeRevalidatePath path=", path);
1150
- try {
1151
- const { revalidatePath } = await nextCacheImport();
1152
- revalidatePath(path);
1153
- } catch (error) {
1154
- console.error("[WWW] render/hooks:_shared:safeRevalidatePath failed path=", path, "err=", String(error));
1155
- payload.logger.error(`revalidatePath("${path}") failed: ${String(error)}`);
1156
- }
1157
- }
1158
- async function safeRevalidateTag(payload, tag, profile = "max") {
1159
- console.log("[WWW] render/hooks:_shared:safeRevalidateTag tag=", tag, "profile=", profile);
1160
- try {
1161
- const { revalidateTag } = await nextCacheImport();
1162
- revalidateTag(tag, profile);
1163
- } catch (error) {
1164
- console.error("[WWW] render/hooks:_shared:safeRevalidateTag failed tag=", tag, "err=", String(error));
1165
- payload.logger.error(`revalidateTag("${tag}") failed: ${String(error)}`);
1166
- }
1167
- }
1168
-
1169
- // src/render/hooks/revalidateCollection.ts
1170
- function createRevalidateCollectionHook(options) {
1171
- const {
1172
- collectionSlug,
1173
- urlPathPrefix = "",
1174
- sitemapTag,
1175
- localePrefix: modeOption,
1176
- defaultLocale: defaultLocaleOption,
1177
- pathMode = "url"
1178
- } = options;
1179
- const resolvedSitemapTag = sitemapTag === false ? false : sitemapTag ?? `${collectionSlug}-sitemap`;
1180
- console.log("[WWW] render/hooks:createRevalidateCollectionHook collectionSlug=", collectionSlug, "urlPathPrefix=", urlPathPrefix, "sitemapTag=", resolvedSitemapTag, "pathMode=", pathMode);
1181
- const resolveDefaults = (req) => {
1182
- const mode = modeOption ?? "always";
1183
- const defaultLocale = defaultLocaleOption ?? req?.payload?.config?.localization?.defaultLocale ?? "";
1184
- return { mode, defaultLocale };
1185
- };
1186
- const localesToFanOut = (req) => {
1187
- const all = allLocales(req);
1188
- if (all.length > 0)
1189
- return all;
1190
- const single = resolveLocale(req);
1191
- return single ? [single] : [];
1192
- };
1193
- const collectionPath = (slug, locale, mode, defaultLocale) => {
1194
- const prefix = prefixFor(locale, defaultLocale, mode);
1195
- if (!slug)
1196
- return `${prefix}${urlPathPrefix}` || "/";
1197
- return `${prefix}${urlPathPrefix}/${slug}`;
1198
- };
1199
- const fanOutPaths = async (payload, req, slug, label) => {
1200
- const { mode, defaultLocale } = resolveDefaults(req);
1201
- const locales = localesToFanOut(req);
1202
- for (const locale of locales) {
1203
- const path = collectionPath(slug, locale, mode, defaultLocale);
1204
- payload.logger.info?.(`${label} ${path}`);
1205
- await safeRevalidatePath(payload, path);
1206
- }
1207
- };
1208
- const fireCollectionTags = async (payload, docId, req) => {
1209
- console.log("[WWW] render/hooks:fireCollectionTags collectionSlug=", collectionSlug, "docId=", docId);
1210
- if (typeof docId === "string" || typeof docId === "number") {
1211
- await safeRevalidateTag(payload, `collection_${collectionSlug}_${docId}`);
1212
- }
1213
- if (resolvedSitemapTag !== false) {
1214
- await safeRevalidateTag(payload, resolvedSitemapTag);
1215
- }
1216
- };
1217
- const afterChange = async ({ doc, previousDoc, req }) => {
1218
- if (shouldSkipRevalidate(req.context))
1219
- return doc;
1220
- const { payload } = req;
1221
- const typed = doc;
1222
- const prev = previousDoc;
1223
- console.log("[WWW] render/hooks:afterChange collectionSlug=", collectionSlug, "id=", typed.id, "slug=", typed.slug, "prevSlug=", prev?.slug);
1224
- const isPublished = typed._status === "published";
1225
- const wasPublished = prev?._status === "published";
1226
- const prevSlugIsString = typeof prev?.slug === "string";
1227
- const slugChanged = prevSlugIsString && prev?.slug !== typed.slug;
1228
- if (isPublished) {
1229
- if (pathMode !== "tag-only") {
1230
- await fanOutPaths(payload, req, typed.slug, `Revalidating ${collectionSlug} at path:`);
1231
- }
1232
- await fireCollectionTags(payload, typed.id, req);
1233
- }
1234
- if (wasPublished && (!isPublished || slugChanged)) {
1235
- if (pathMode !== "tag-only") {
1236
- await fanOutPaths(payload, req, prev?.slug, `Revalidating old ${collectionSlug} at path:`);
1237
- }
1238
- await fireCollectionTags(payload, typed.id, req);
1239
- }
1240
- return doc;
1241
- };
1242
- const afterDelete = async ({ doc, req }) => {
1243
- if (shouldSkipRevalidate(req.context))
1244
- return doc ?? null;
1245
- const { payload } = req;
1246
- const typed = doc;
1247
- console.log("[WWW] render/hooks:afterDelete collectionSlug=", collectionSlug, "id=", typed?.id, "slug=", typed?.slug);
1248
- if (pathMode !== "tag-only") {
1249
- await fanOutPaths(payload, req, typed?.slug, `Revalidating deleted ${collectionSlug} at path:`);
1250
- }
1251
- await fireCollectionTags(payload, typed?.id, req);
1252
- return doc ?? null;
1253
- };
1254
- return { afterChange, afterDelete };
1255
- }
1256
- var createRevalidatePageHooks = (opts = {}) => {
1257
- console.log("[WWW] render/hooks:createRevalidatePageHooks (deprecated alias) opts=", JSON.stringify(opts));
1258
- return createRevalidateCollectionHook({
1259
- collectionSlug: "pages",
1260
- urlPathPrefix: "",
1261
- ...opts
1262
- });
1263
- };
1264
-
1265
- // src/data/collections/StaticPages/index.ts
1266
- var createStaticPagesCollection = (blocks) => {
1267
- const { afterChange, afterDelete } = createRevalidateCollectionHook({
1268
- collectionSlug: STATIC_PAGES_SLUG,
1269
- pathMode: "tag-only",
1270
- sitemapTag: "static-pages"
1271
- });
1272
- return {
1273
- slug: STATIC_PAGES_SLUG,
1274
- dbName: "sp",
1275
- admin: { group: "System", useAsTitle: "title" },
1276
- access: {
1277
- create: authenticated,
1278
- delete: authenticated,
1279
- read: authenticatedOrPublished,
1280
- update: authenticated
1281
- },
1282
- fields: [
1283
- {
1284
- name: "kind",
1285
- type: "select",
1286
- required: true,
1287
- unique: true,
1288
- index: true,
1289
- options: [
1290
- { label: "Not found (404)", value: "not-found" },
1291
- { label: "Server error (500)", value: "server-error" },
1292
- { label: "Search empty", value: "search-empty" },
1293
- { label: "Offline", value: "offline" }
1294
- ],
1295
- admin: {
1296
- position: "sidebar",
1297
- description: "Which system page this row powers. One row per kind."
1298
- }
1299
- },
1300
- {
1301
- name: "title",
1302
- type: "text",
1303
- required: true,
1304
- localized: true,
1305
- admin: { description: "Admin-only label. Not rendered." }
1306
- },
1307
- {
1308
- type: "tabs",
1309
- tabs: [
1310
- {
1311
- fields: [
1312
- {
1313
- name: "blocks",
1314
- type: "blocks",
1315
- localized: true,
1316
- blocks,
1317
- admin: { initCollapsed: true },
1318
- dbName: "b"
1319
- }
1320
- ],
1321
- label: "Content"
1322
- }
1323
- ]
1324
- },
1325
- {
1326
- name: "publishedAt",
1327
- type: "date",
1328
- admin: { position: "sidebar" }
1329
- }
1330
- ],
1331
- hooks: {
1332
- afterChange: [afterChange],
1333
- afterDelete: [afterDelete]
1334
- },
1335
- versions: { drafts: { autosave: { interval: 1000 } } }
1336
- };
1337
- };
1338
-
1339
- // src/render/pages/createStaticPageExports.tsx
1340
- import { jsx as jsx9 } from "react/jsx-runtime";
1341
- function createStaticPageExports({
1342
- kind = "not-found",
1343
- config: configPromise,
1344
- importMap: importMapArg
1345
- }) {
1346
- const importMap = importMapArg ?? {};
1347
- let dbgRenderCount = 0;
1348
- const default_ = async () => {
1349
- const { getLocale } = await import("next-intl/server");
1350
- const locale = await getLocale();
1351
- console.log("[WWW] render/pages:createStaticPageExports:default_ kind=", kind, "locale=", locale);
1352
- dbgRenderCount++;
1353
- {
1354
- let reqUrl = "?";
1355
- try {
1356
- const { headers } = await import("next/headers");
1357
- const h = await headers();
1358
- reqUrl = h.get("x-invoke-path") || h.get("x-matched-path") || h.get("x-next-url") || h.get("next-url") || h.get("referer") || "?";
1359
- } catch {}
1360
- console.error(`[WWW-DBG static-render #${dbgRenderCount}] kind=${kind} locale=${locale} url=${reqUrl}`);
1361
- if (dbgRenderCount <= 5) {
1362
- console.error(`[WWW-DBG static-render #${dbgRenderCount}] stack:
1363
- ` + (new Error("static-render").stack?.split(`
1364
- `).slice(2, 12).join(`
1365
- `) ?? ""));
1366
- }
1367
- }
1368
- const doc = await queryDocBySlug({
1369
- collectionSlug: STATIC_PAGES_SLUG,
1370
- slug: kind,
1371
- slugField: "kind",
1372
- locale,
1373
- config: configPromise
1374
- });
1375
- if (!doc) {
1376
- console.warn("[createStaticPageExports] !doc: STATIC_PAGES_SLUG=", STATIC_PAGES_SLUG, "slug:" + kind);
1377
- return /* @__PURE__ */ jsx9("section", {
1378
- children: /* @__PURE__ */ jsx9("h1", {
1379
- children: "404"
1380
- })
1381
- });
1382
- }
1383
- const cfg = await configPromise;
1384
- console.log("[WWW] render/pages:createStaticPageExports:default_ -> rendering via PagesPage kind=", kind, "locale=", locale);
1385
- return /* @__PURE__ */ jsx9(PagesPage, {
1386
- doc,
1387
- locale,
1388
- importMap,
1389
- config: cfg
1390
- });
1391
- };
1392
- return { default: default_ };
1393
- }
1394
-
1395
580
  // src/exports/render-pages.ts
1396
- init_PageShowcase();
1397
-
1398
- // src/render/pages/PostsPage.tsx
1399
- import { RichText as RichText2 } from "@payloadcms/richtext-lexical/react";
1400
- import { jsx as jsx10, jsxs as jsxs5, Fragment as Fragment6 } from "react/jsx-runtime";
1401
- async function PostsPage({ doc, locale, importMap: _importMap }) {
1402
- if (!doc) {
1403
- console.log("[WWW] render/pages:PostsPage no doc");
1404
- return /* @__PURE__ */ jsx10(Fragment6, {});
1405
- }
1406
- const title = readText(doc.title, locale);
1407
- const excerpt = readText(doc.excerpt, locale);
1408
- const content = doc.content;
1409
- console.log("[WWW] render/pages:PostsPage titleLen=", title.length, "excerptLen=", excerpt.length, "hasContent=", Boolean(content), "locale=", locale);
1410
- return /* @__PURE__ */ jsxs5("article", {
1411
- className: "posts-page prose prose-neutral dark:prose-invert mx-auto max-w-3xl py-10",
1412
- children: [
1413
- /* @__PURE__ */ jsxs5("header", {
1414
- className: "posts-page__header not-prose mb-8",
1415
- children: [
1416
- /* @__PURE__ */ jsx10("h1", {
1417
- className: "posts-page__title text-4xl font-semibold tracking-tight",
1418
- children: title
1419
- }),
1420
- excerpt ? /* @__PURE__ */ jsx10("p", {
1421
- className: "posts-page__excerpt mt-3 text-lg text-muted-foreground",
1422
- children: excerpt
1423
- }) : null
1424
- ]
1425
- }),
1426
- content ? /* @__PURE__ */ jsx10("div", {
1427
- className: "posts-page__content",
1428
- children: /* @__PURE__ */ jsx10(RichText2, {
1429
- data: content
1430
- })
1431
- }) : null
1432
- ]
1433
- });
1434
- }
1435
- function readText(value, preferredLocale) {
1436
- if (typeof value !== "string")
1437
- return "";
1438
- if (!value.startsWith("{"))
1439
- return value;
1440
- try {
1441
- const parsed = JSON.parse(value);
1442
- if (typeof parsed === "string")
1443
- return parsed;
1444
- if (parsed && typeof parsed === "object") {
1445
- const obj = parsed;
1446
- if (preferredLocale && typeof obj[preferredLocale] === "string" && obj[preferredLocale].length > 0) {
1447
- return obj[preferredLocale];
1448
- }
1449
- const first = Object.values(obj).find((v) => typeof v === "string" && v.length > 0);
1450
- return typeof first === "string" ? first : value;
1451
- }
1452
- return value;
1453
- } catch {
1454
- return value;
1455
- }
1456
- }
1457
-
1458
- // src/render/pages/HeaderPage.tsx
1459
- import"server-only";
1460
- import { jsx as jsx11, jsxs as jsxs6, Fragment as Fragment7 } from "react/jsx-runtime";
1461
- function HeaderPage({ data, locale: _locale }) {
1462
- if (!data) {
1463
- console.log("[WWW] render/pages:HeaderPage no data");
1464
- return /* @__PURE__ */ jsx11(Fragment7, {});
1465
- }
1466
- const nav = data.nav ?? [];
1467
- const items = nav.filter((b) => b.blockType === "navItem");
1468
- const columns = nav.filter((b) => b.blockType === "navColumn");
1469
- console.log("[WWW] render/pages:HeaderPage items=", items.length, "columns=", columns.length, "locale=", _locale);
1470
- const renderLink = (link, fallbackHref = "#") => {
1471
- if (!link)
1472
- return /* @__PURE__ */ jsx11("a", {
1473
- href: fallbackHref,
1474
- children: link?.label ?? ""
1475
- });
1476
- if (link.type === "custom" && typeof link.url === "string") {
1477
- return /* @__PURE__ */ jsx11("a", {
1478
- href: link.url,
1479
- children: link.label
1480
- });
1481
- }
1482
- if (link.type === "reference" && link.reference) {
1483
- const ref = link.reference;
1484
- if (typeof ref === "object" && ref.slug) {
1485
- return /* @__PURE__ */ jsx11("a", {
1486
- href: `/${ref.slug}`,
1487
- children: link.label
1488
- });
1489
- }
1490
- }
1491
- return /* @__PURE__ */ jsx11("a", {
1492
- href: fallbackHref,
1493
- children: link.label ?? ""
1494
- });
1495
- };
1496
- return /* @__PURE__ */ jsxs6("nav", {
1497
- children: [
1498
- items.map((item, i) => /* @__PURE__ */ jsx11("span", {
1499
- style: { marginRight: 16 },
1500
- children: renderLink(item.link)
1501
- }, `item-${i}`)),
1502
- columns.map((col, i) => /* @__PURE__ */ jsxs6("div", {
1503
- style: { display: "inline-block", marginRight: 24, verticalAlign: "top" },
1504
- children: [
1505
- col.title ? /* @__PURE__ */ jsx11("strong", {
1506
- children: col.title
1507
- }) : null,
1508
- /* @__PURE__ */ jsx11("div", {
1509
- children: (col.links ?? []).map((entry, j) => /* @__PURE__ */ jsx11("div", {
1510
- children: renderLink(entry.link)
1511
- }, `col-${i}-link-${j}`))
1512
- })
1513
- ]
1514
- }, `col-${i}`))
1515
- ]
1516
- });
1517
- }
1518
-
1519
- // src/render/pages/FooterPage.tsx
1520
- import"server-only";
1521
- import { jsx as jsx12, jsxs as jsxs7, Fragment as Fragment8 } from "react/jsx-runtime";
1522
- function FooterPage({ data, locale: _locale }) {
1523
- if (!data) {
1524
- console.log("[WWW] render/pages:FooterPage no data");
1525
- return /* @__PURE__ */ jsx12(Fragment8, {});
1526
- }
1527
- const nav = data.nav ?? [];
1528
- const items = nav.filter((b) => b.blockType === "navItem");
1529
- const columns = nav.filter((b) => b.blockType === "navColumn");
1530
- console.log("[WWW] render/pages:FooterPage items=", items.length, "columns=", columns.length, "locale=", _locale);
1531
- const renderLink = (link, fallbackHref = "#") => {
1532
- if (!link)
1533
- return /* @__PURE__ */ jsx12("a", {
1534
- href: fallbackHref,
1535
- children: link?.label ?? ""
1536
- });
1537
- if (link.type === "custom" && typeof link.url === "string") {
1538
- return /* @__PURE__ */ jsx12("a", {
1539
- href: link.url,
1540
- children: link.label
1541
- });
1542
- }
1543
- if (link.type === "reference" && link.reference) {
1544
- const ref = link.reference;
1545
- if (typeof ref === "object" && ref.slug) {
1546
- return /* @__PURE__ */ jsx12("a", {
1547
- href: `/${ref.slug}`,
1548
- children: link.label
1549
- });
1550
- }
1551
- }
1552
- return /* @__PURE__ */ jsx12("a", {
1553
- href: fallbackHref,
1554
- children: link.label ?? ""
1555
- });
1556
- };
1557
- return /* @__PURE__ */ jsx12("footer", {
1558
- children: /* @__PURE__ */ jsxs7("div", {
1559
- children: [
1560
- items.map((item, i) => /* @__PURE__ */ jsx12("span", {
1561
- style: { marginRight: 16 },
1562
- children: renderLink(item.link)
1563
- }, `item-${i}`)),
1564
- columns.map((col, i) => /* @__PURE__ */ jsxs7("div", {
1565
- style: { display: "inline-block", marginRight: 24, verticalAlign: "top" },
1566
- children: [
1567
- col.title ? /* @__PURE__ */ jsx12("strong", {
1568
- children: col.title
1569
- }) : null,
1570
- /* @__PURE__ */ jsx12("div", {
1571
- children: (col.links ?? []).map((entry, j) => /* @__PURE__ */ jsx12("div", {
1572
- children: renderLink(entry.link)
1573
- }, `col-${i}-link-${j}`))
1574
- })
1575
- ]
1576
- }, `col-${i}`))
1577
- ]
1578
- })
1579
- });
1580
- }
1581
-
1582
- // src/exports/render-pages.ts
1583
- var PageShowcase2 = PageShowcase;
1584
- var render_pages_default = {
1585
- addCollectionsToSitemap,
1586
- createCollectionPageExports,
1587
- createRootLayoutExports,
1588
- createStaticPageExports,
1589
- HeaderPage,
1590
- FooterPage,
1591
- PagesPage,
1592
- PostsPage,
1593
- PageShowcase: PageShowcase2
1594
- };
581
+ import { RootJsonLd as RootJsonLd2 } from "@justanarthur/payload-plugin-seo/root-jsonld";
582
+ var renderPages = { createCollectionPageExports, createRootLayoutExports, PagesPage, PostsPage, HeaderPage, FooterPage, RootJsonLd: RootJsonLd2 };
583
+ var render_pages_default = renderPages;
1595
584
  export {
1596
585
  render_pages_default as default,
1597
- createStaticPageExports,
1598
586
  createRootLayoutExports,
1599
587
  createCollectionPageExports,
1600
- addCollectionsToSitemap,
588
+ RootJsonLd2 as RootJsonLd,
1601
589
  PostsPage,
1602
590
  PagesPage,
1603
- PageShowcase2 as PageShowcase,
1604
591
  HeaderPage,
1605
592
  FooterPage
1606
593
  };