@justanarthur/payload-www 0.1.1

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