@justanarthur/payload-www 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocks.js +6 -2
- package/dist/collections.js +47 -15
- package/dist/components.js +1 -0
- package/dist/config.js +79 -21
- package/dist/core-blocks.js +6 -2
- package/dist/core-utils.js +5 -1
- package/dist/data-collections.js +47 -15
- package/dist/data-test.js +79 -21
- package/dist/globals.js +10 -1
- package/dist/hooks.js +47 -15
- package/dist/index.js +1 -0
- package/dist/metadata.js +64 -21
- package/dist/pages.js +118 -36
- package/dist/render-components.js +13 -3
- package/dist/render-metadata.js +64 -21
- package/dist/render-pages.js +178 -53
- package/dist/render-utils.js +58 -15
- package/dist/server.js +179 -56
- package/dist/test.js +79 -21
- package/dist/utils.js +5 -1
- package/dist/with-www-config.js +79 -21
- package/package.json +1 -1
package/dist/test.js
CHANGED
|
@@ -60,30 +60,45 @@ var slugField = (options = {}) => {
|
|
|
60
60
|
|
|
61
61
|
// src/render/_locale.ts
|
|
62
62
|
function prefixFor(locale, defaultLocale, mode) {
|
|
63
|
+
let result;
|
|
63
64
|
if (mode === "never")
|
|
64
|
-
|
|
65
|
-
if (mode === "as-needed" && locale === defaultLocale)
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
result = "";
|
|
66
|
+
else if (mode === "as-needed" && locale === defaultLocale)
|
|
67
|
+
result = "";
|
|
68
|
+
else
|
|
69
|
+
result = `/${locale}`;
|
|
70
|
+
console.log("[WWW] render/_locale:prefixFor locale=", locale, "default=", defaultLocale, "mode=", mode, "->", JSON.stringify(result));
|
|
71
|
+
return result;
|
|
68
72
|
}
|
|
69
73
|
function resolveLocale(req) {
|
|
70
|
-
if (!req || typeof req !== "object")
|
|
74
|
+
if (!req || typeof req !== "object") {
|
|
75
|
+
console.log('[WWW] render/_locale:resolveLocale -> "" (no req)');
|
|
71
76
|
return "";
|
|
77
|
+
}
|
|
72
78
|
const r = req;
|
|
73
|
-
if (typeof r.locale === "string" && r.locale.length > 0)
|
|
79
|
+
if (typeof r.locale === "string" && r.locale.length > 0) {
|
|
80
|
+
console.log("[WWW] render/_locale:resolveLocale ->", r.locale, "(from req.locale)");
|
|
74
81
|
return r.locale;
|
|
82
|
+
}
|
|
75
83
|
const fallback = r.payload?.config?.localization?.defaultLocale;
|
|
76
|
-
if (typeof fallback === "string" && fallback.length > 0)
|
|
84
|
+
if (typeof fallback === "string" && fallback.length > 0) {
|
|
85
|
+
console.log("[WWW] render/_locale:resolveLocale ->", fallback, "(from config.localization.defaultLocale)");
|
|
77
86
|
return fallback;
|
|
87
|
+
}
|
|
88
|
+
console.log('[WWW] render/_locale:resolveLocale -> "" (no locale anywhere)');
|
|
78
89
|
return "";
|
|
79
90
|
}
|
|
80
91
|
function allLocales(req) {
|
|
81
|
-
if (!req || typeof req !== "object")
|
|
92
|
+
if (!req || typeof req !== "object") {
|
|
93
|
+
console.log("[WWW] render/_locale:allLocales -> [] (no req)");
|
|
82
94
|
return [];
|
|
95
|
+
}
|
|
83
96
|
const r = req;
|
|
84
97
|
const list = r.payload?.config?.localization?.locales;
|
|
85
|
-
if (!Array.isArray(list) || list.length === 0)
|
|
98
|
+
if (!Array.isArray(list) || list.length === 0) {
|
|
99
|
+
console.log("[WWW] render/_locale:allLocales -> [] (no locales declared)");
|
|
86
100
|
return [];
|
|
101
|
+
}
|
|
87
102
|
const out = [];
|
|
88
103
|
for (const entry of list) {
|
|
89
104
|
if (typeof entry === "string" && entry.length > 0) {
|
|
@@ -94,6 +109,7 @@ function allLocales(req) {
|
|
|
94
109
|
out.push(code);
|
|
95
110
|
}
|
|
96
111
|
}
|
|
112
|
+
console.log("[WWW] render/_locale:allLocales ->", JSON.stringify(out));
|
|
97
113
|
return out;
|
|
98
114
|
}
|
|
99
115
|
|
|
@@ -103,21 +119,28 @@ function nextCacheImport() {
|
|
|
103
119
|
return cachePromise ??= import("next/cache");
|
|
104
120
|
}
|
|
105
121
|
function shouldSkipRevalidate(context) {
|
|
106
|
-
|
|
122
|
+
const skip = Boolean(context?.disableRevalidate);
|
|
123
|
+
if (skip)
|
|
124
|
+
console.log("[WWW] render/hooks:_shared:shouldSkipRevalidate -> skip");
|
|
125
|
+
return skip;
|
|
107
126
|
}
|
|
108
127
|
async function safeRevalidatePath(payload, path) {
|
|
128
|
+
console.log("[WWW] render/hooks:_shared:safeRevalidatePath path=", path);
|
|
109
129
|
try {
|
|
110
130
|
const { revalidatePath } = await nextCacheImport();
|
|
111
131
|
revalidatePath(path);
|
|
112
132
|
} catch (error) {
|
|
133
|
+
console.error("[WWW] render/hooks:_shared:safeRevalidatePath failed path=", path, "err=", String(error));
|
|
113
134
|
payload.logger.error(`revalidatePath("${path}") failed: ${String(error)}`);
|
|
114
135
|
}
|
|
115
136
|
}
|
|
116
137
|
async function safeRevalidateTag(payload, tag, profile = "max") {
|
|
138
|
+
console.log("[WWW] render/hooks:_shared:safeRevalidateTag tag=", tag, "profile=", profile);
|
|
117
139
|
try {
|
|
118
140
|
const { revalidateTag } = await nextCacheImport();
|
|
119
141
|
revalidateTag(tag, profile);
|
|
120
142
|
} catch (error) {
|
|
143
|
+
console.error("[WWW] render/hooks:_shared:safeRevalidateTag failed tag=", tag, "err=", String(error));
|
|
121
144
|
payload.logger.error(`revalidateTag("${tag}") failed: ${String(error)}`);
|
|
122
145
|
}
|
|
123
146
|
}
|
|
@@ -133,6 +156,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
133
156
|
pathMode = "url"
|
|
134
157
|
} = options;
|
|
135
158
|
const resolvedSitemapTag = sitemapTag === false ? false : sitemapTag ?? `${collectionSlug}-sitemap`;
|
|
159
|
+
console.log("[WWW] render/hooks:createRevalidateCollectionHook collectionSlug=", collectionSlug, "urlPathPrefix=", urlPathPrefix, "sitemapTag=", resolvedSitemapTag, "pathMode=", pathMode);
|
|
136
160
|
const resolveDefaults = (req) => {
|
|
137
161
|
const mode = modeOption ?? "always";
|
|
138
162
|
const defaultLocale = defaultLocaleOption ?? req?.payload?.config?.localization?.defaultLocale ?? "";
|
|
@@ -161,6 +185,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
161
185
|
}
|
|
162
186
|
};
|
|
163
187
|
const fireCollectionTags = async (payload, docId, req) => {
|
|
188
|
+
console.log("[WWW] render/hooks:fireCollectionTags collectionSlug=", collectionSlug, "docId=", docId);
|
|
164
189
|
if (typeof docId === "string" || typeof docId === "number") {
|
|
165
190
|
await safeRevalidateTag(payload, `collection_${collectionSlug}_${docId}`);
|
|
166
191
|
}
|
|
@@ -174,6 +199,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
174
199
|
const { payload } = req;
|
|
175
200
|
const typed = doc;
|
|
176
201
|
const prev = previousDoc;
|
|
202
|
+
console.log("[WWW] render/hooks:afterChange collectionSlug=", collectionSlug, "id=", typed.id, "slug=", typed.slug, "prevSlug=", prev?.slug);
|
|
177
203
|
const isPublished = typed._status === "published";
|
|
178
204
|
const wasPublished = prev?._status === "published";
|
|
179
205
|
const prevSlugIsString = typeof prev?.slug === "string";
|
|
@@ -197,6 +223,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
197
223
|
return doc ?? null;
|
|
198
224
|
const { payload } = req;
|
|
199
225
|
const typed = doc;
|
|
226
|
+
console.log("[WWW] render/hooks:afterDelete collectionSlug=", collectionSlug, "id=", typed?.id, "slug=", typed?.slug);
|
|
200
227
|
if (pathMode !== "tag-only") {
|
|
201
228
|
await fanOutPaths(payload, req, typed?.slug, `Revalidating deleted ${collectionSlug} at path:`);
|
|
202
229
|
}
|
|
@@ -205,11 +232,14 @@ function createRevalidateCollectionHook(options) {
|
|
|
205
232
|
};
|
|
206
233
|
return { afterChange, afterDelete };
|
|
207
234
|
}
|
|
208
|
-
var createRevalidatePageHooks = (opts = {}) =>
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
235
|
+
var createRevalidatePageHooks = (opts = {}) => {
|
|
236
|
+
console.log("[WWW] render/hooks:createRevalidatePageHooks (deprecated alias) opts=", JSON.stringify(opts));
|
|
237
|
+
return createRevalidateCollectionHook({
|
|
238
|
+
collectionSlug: "pages",
|
|
239
|
+
urlPathPrefix: "",
|
|
240
|
+
...opts
|
|
241
|
+
});
|
|
242
|
+
};
|
|
213
243
|
|
|
214
244
|
// src/config/constants.ts
|
|
215
245
|
var PAGES_RENDER_PATH = "@justanarthur/payload-www/render-pages#PagesPage";
|
|
@@ -517,10 +547,12 @@ var link = (options = {}) => {
|
|
|
517
547
|
|
|
518
548
|
// src/render/hooks/revalidateGlobal.ts
|
|
519
549
|
function createRevalidateGlobalHook(slug) {
|
|
550
|
+
console.log("[WWW] render/hooks:createRevalidateGlobalHook slug=", slug);
|
|
520
551
|
return async ({ doc, req: { payload, context, locale } }) => {
|
|
521
552
|
if (shouldSkipRevalidate(context))
|
|
522
553
|
return doc;
|
|
523
554
|
const tags = [`global_${slug}`, `global_${slug}_${locale}`];
|
|
555
|
+
console.log("[WWW] render/hooks:revalidateGlobal slug=", slug, "locale=", locale, "tags=", JSON.stringify(tags));
|
|
524
556
|
payload.logger.info?.(`Revalidating global: ${tags.join(", ")}`);
|
|
525
557
|
for (const tag of tags) {
|
|
526
558
|
await safeRevalidateTag(payload, tag);
|
|
@@ -615,11 +647,14 @@ function createPreviewHandler(options) {
|
|
|
615
647
|
const url = new URL(req.url);
|
|
616
648
|
const path = url.searchParams.get("path") ?? "/";
|
|
617
649
|
const previewSecret = url.searchParams.get("previewSecret");
|
|
650
|
+
console.log("[WWW] render/preview:createPreviewHandler:GET path=", path, "hasSecret=", Boolean(previewSecret), "enableDraftMode=", enableDraftMode);
|
|
618
651
|
if (!previewSecret || previewSecret !== secret) {
|
|
652
|
+
console.warn("[WWW] render/preview:createPreviewHandler:GET invalid preview secret (401)");
|
|
619
653
|
return new Response("Invalid preview secret", { status: 401 });
|
|
620
654
|
}
|
|
621
655
|
if (enableDraftMode) {
|
|
622
656
|
(await draftMode()).enable();
|
|
657
|
+
console.log("[WWW] render/preview:createPreviewHandler:GET draftMode enabled");
|
|
623
658
|
}
|
|
624
659
|
redirect(path);
|
|
625
660
|
return new Response(null, { status: 204 });
|
|
@@ -639,6 +674,7 @@ async function buildHreflangAlternates({
|
|
|
639
674
|
localePrefix = "always"
|
|
640
675
|
}) {
|
|
641
676
|
const allLocaleSlugs = await queryAllLocaleSlugs(storedSlug, locale);
|
|
677
|
+
console.log("[WWW] render/metadata:buildHreflangAlternates storedSlug=", storedSlug, "locale=", locale, "allLocaleSlugs=", JSON.stringify(allLocaleSlugs));
|
|
642
678
|
const languages = {};
|
|
643
679
|
const urlFor = (l, slug) => {
|
|
644
680
|
const trimmedPrefix = urlPrefix.replace(/^\/|\/$/g, "");
|
|
@@ -656,6 +692,7 @@ async function buildHreflangAlternates({
|
|
|
656
692
|
if (allLocaleSlugs?.[defaultLocale]) {
|
|
657
693
|
languages["x-default"] = urlFor(defaultLocale, allLocaleSlugs[defaultLocale]);
|
|
658
694
|
}
|
|
695
|
+
console.log("[WWW] render/metadata:buildHreflangAlternates ->", JSON.stringify(languages));
|
|
659
696
|
return languages;
|
|
660
697
|
}
|
|
661
698
|
|
|
@@ -677,6 +714,7 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
|
|
|
677
714
|
draft = false,
|
|
678
715
|
config
|
|
679
716
|
}) {
|
|
717
|
+
console.log("[WWW] render/metadata:queryDocBySlug collection=", collectionSlug, "slug=", slug, "slugField=", slugField2, "locale=", locale, "draft=", draft);
|
|
680
718
|
const payload = await getPayload({ config });
|
|
681
719
|
const result = await payload.find({
|
|
682
720
|
collection: collectionSlug,
|
|
@@ -687,7 +725,9 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
|
|
|
687
725
|
where: { [slugField2]: { equals: slug } },
|
|
688
726
|
locale
|
|
689
727
|
});
|
|
690
|
-
|
|
728
|
+
const doc = result.docs?.[0] ?? null;
|
|
729
|
+
console.log("[WWW] render/metadata:queryDocBySlug ->", doc ? "hit" : "miss");
|
|
730
|
+
return doc;
|
|
691
731
|
});
|
|
692
732
|
var queryAllDocs = cache(async function queryAllDocs2({
|
|
693
733
|
collectionSlug,
|
|
@@ -695,6 +735,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
|
|
|
695
735
|
locale,
|
|
696
736
|
config
|
|
697
737
|
}) {
|
|
738
|
+
console.log("[WWW] render/metadata:queryAllDocs collection=", collectionSlug, "locale=", locale);
|
|
698
739
|
const payload = await getPayload({ config });
|
|
699
740
|
const result = await payload.find({
|
|
700
741
|
collection: collectionSlug,
|
|
@@ -705,7 +746,9 @@ var queryAllDocs = cache(async function queryAllDocs2({
|
|
|
705
746
|
select: { [slugField2]: true },
|
|
706
747
|
locale
|
|
707
748
|
});
|
|
708
|
-
|
|
749
|
+
const docs = result.docs ?? [];
|
|
750
|
+
console.log("[WWW] render/metadata:queryAllDocs -> count=", docs.length);
|
|
751
|
+
return docs;
|
|
709
752
|
});
|
|
710
753
|
var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
711
754
|
collectionSlug,
|
|
@@ -714,6 +757,7 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
|
714
757
|
locale,
|
|
715
758
|
config
|
|
716
759
|
}) {
|
|
760
|
+
console.log("[WWW] render/metadata:queryAllLocaleSlugs collection=", collectionSlug, "slug=", slug, "locale=", locale);
|
|
717
761
|
const payload = await getPayload({ config });
|
|
718
762
|
const result = await payload.find({
|
|
719
763
|
collection: collectionSlug,
|
|
@@ -726,8 +770,10 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
|
726
770
|
select: { [slugField2]: true }
|
|
727
771
|
});
|
|
728
772
|
const doc = result.docs?.[0];
|
|
729
|
-
if (!doc)
|
|
773
|
+
if (!doc) {
|
|
774
|
+
console.log("[WWW] render/metadata:queryAllLocaleSlugs -> undefined (no doc)");
|
|
730
775
|
return;
|
|
776
|
+
}
|
|
731
777
|
let fieldValue = doc[slugField2];
|
|
732
778
|
if (doc.id != null) {
|
|
733
779
|
const allLocales2 = await payload.findByID({
|
|
@@ -742,6 +788,7 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
|
742
788
|
fieldValue = allLocales2[slugField2];
|
|
743
789
|
}
|
|
744
790
|
if (fieldValue && typeof fieldValue === "object") {
|
|
791
|
+
console.log("[WWW] render/metadata:queryAllLocaleSlugs -> localized map=", JSON.stringify(fieldValue));
|
|
745
792
|
return fieldValue;
|
|
746
793
|
}
|
|
747
794
|
const resolved = await config;
|
|
@@ -749,6 +796,7 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
|
749
796
|
const out = {};
|
|
750
797
|
for (const l of rawLocales)
|
|
751
798
|
out[l] = String(fieldValue ?? slug);
|
|
799
|
+
console.log("[WWW] render/metadata:queryAllLocaleSlugs -> flat-fanout locales=", rawLocales.length, "slug=", JSON.stringify(fieldValue ?? slug));
|
|
752
800
|
return out;
|
|
753
801
|
});
|
|
754
802
|
var queryGlobal = cache(async function queryGlobal2({
|
|
@@ -758,6 +806,7 @@ var queryGlobal = cache(async function queryGlobal2({
|
|
|
758
806
|
draft = false,
|
|
759
807
|
config
|
|
760
808
|
}) {
|
|
809
|
+
console.log("[WWW] render/metadata:queryGlobal global=", globalSlug, "locale=", locale, "depth=", depth, "draft=", draft);
|
|
761
810
|
const payload = await getPayload({ config });
|
|
762
811
|
try {
|
|
763
812
|
const global = await payload.findGlobal({
|
|
@@ -766,27 +815,35 @@ var queryGlobal = cache(async function queryGlobal2({
|
|
|
766
815
|
draft,
|
|
767
816
|
locale
|
|
768
817
|
});
|
|
818
|
+
console.log("[WWW] render/metadata:queryGlobal -> hit");
|
|
769
819
|
return global;
|
|
770
|
-
} catch {
|
|
820
|
+
} catch (error) {
|
|
821
|
+
console.warn("[WWW] render/metadata:queryGlobal failed for slug=", globalSlug, "err=", String(error));
|
|
771
822
|
return null;
|
|
772
823
|
}
|
|
773
824
|
});
|
|
774
825
|
function getRenderModuleExports(exportName, collection, importMap) {
|
|
775
826
|
const path = collection?.custom?.path;
|
|
776
|
-
if (!path)
|
|
827
|
+
if (!path) {
|
|
828
|
+
console.log("[WWW] render/metadata:getRenderModuleExports no custom.path exportName=", exportName);
|
|
777
829
|
return;
|
|
830
|
+
}
|
|
778
831
|
const mod = getFromImportMap(path, importMap);
|
|
779
|
-
|
|
832
|
+
const value = mod?.[exportName];
|
|
833
|
+
console.log("[WWW] render/metadata:getRenderModuleExports exportName=", exportName, "path=", path, "hit=", Boolean(value));
|
|
834
|
+
return value;
|
|
780
835
|
}
|
|
781
836
|
|
|
782
837
|
// src/render/sitemap/createSitemapFile.ts
|
|
783
838
|
function createSitemapFile(options) {
|
|
784
839
|
const { collections } = options;
|
|
785
840
|
return async function sitemap() {
|
|
841
|
+
console.log("[WWW] render/sitemap:createSitemapFile:sitemap collections=", JSON.stringify(options.collections), "localePrefix=", options.localePrefix ?? "always");
|
|
786
842
|
const cfg = await options.config;
|
|
787
843
|
const allLocales2 = Array.isArray(cfg.localization?.locales) ? cfg.localization.locales.map((l) => typeof l === "string" ? l : l.code) : [cfg.localization?.defaultLocale ?? "en"];
|
|
788
844
|
const defaultLocale = cfg.localization?.defaultLocale ?? allLocales2[0];
|
|
789
845
|
const activeLocales = Array.isArray(options.locales) && options.locales.length > 0 ? options.locales.filter((l) => allLocales2.includes(l)) : allLocales2;
|
|
846
|
+
console.log("[WWW] render/sitemap:createSitemapFile:sitemap allLocales=", JSON.stringify(allLocales2), "default=", defaultLocale, "active=", JSON.stringify(activeLocales));
|
|
790
847
|
const entries = [];
|
|
791
848
|
const seen = new Set;
|
|
792
849
|
for (const collectionSlug of collections) {
|
|
@@ -842,6 +899,7 @@ function createSitemapFile(options) {
|
|
|
842
899
|
}
|
|
843
900
|
}
|
|
844
901
|
}
|
|
902
|
+
console.log("[WWW] render/sitemap:createSitemapFile:sitemap -> entries=", entries.length);
|
|
845
903
|
return entries;
|
|
846
904
|
};
|
|
847
905
|
}
|
package/dist/utils.js
CHANGED
|
@@ -36,13 +36,17 @@ function generateImportName(type, slug) {
|
|
|
36
36
|
import { jsx } from "react/jsx-runtime";
|
|
37
37
|
function renderCollectionModule(collection = [], slug, importMap, props) {
|
|
38
38
|
const renderPath = collection?.find((c) => c.slug === slug)?.custom?.path;
|
|
39
|
-
if (!renderPath)
|
|
39
|
+
if (!renderPath) {
|
|
40
|
+
console.log("[WWW] render/utils:renderCollectionModule no custom.path slug=", slug);
|
|
40
41
|
return null;
|
|
42
|
+
}
|
|
41
43
|
const CollectionRenderModule = getFromImportMap(renderPath, importMap);
|
|
42
44
|
if (!CollectionRenderModule) {
|
|
45
|
+
console.error("[WWW] render/utils:renderCollectionModule not found slug=", slug, "path=", renderPath);
|
|
43
46
|
if (false) {}
|
|
44
47
|
return null;
|
|
45
48
|
}
|
|
49
|
+
console.log("[WWW] render/utils:renderCollectionModule rendering slug=", slug, "path=", renderPath);
|
|
46
50
|
return /* @__PURE__ */ jsx(CollectionRenderModule, {
|
|
47
51
|
importMap,
|
|
48
52
|
...props
|
package/dist/with-www-config.js
CHANGED
|
@@ -54,30 +54,45 @@ var slugField = (options = {}) => {
|
|
|
54
54
|
|
|
55
55
|
// src/render/_locale.ts
|
|
56
56
|
function prefixFor(locale, defaultLocale, mode) {
|
|
57
|
+
let result;
|
|
57
58
|
if (mode === "never")
|
|
58
|
-
|
|
59
|
-
if (mode === "as-needed" && locale === defaultLocale)
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
result = "";
|
|
60
|
+
else if (mode === "as-needed" && locale === defaultLocale)
|
|
61
|
+
result = "";
|
|
62
|
+
else
|
|
63
|
+
result = `/${locale}`;
|
|
64
|
+
console.log("[WWW] render/_locale:prefixFor locale=", locale, "default=", defaultLocale, "mode=", mode, "->", JSON.stringify(result));
|
|
65
|
+
return result;
|
|
62
66
|
}
|
|
63
67
|
function resolveLocale(req) {
|
|
64
|
-
if (!req || typeof req !== "object")
|
|
68
|
+
if (!req || typeof req !== "object") {
|
|
69
|
+
console.log('[WWW] render/_locale:resolveLocale -> "" (no req)');
|
|
65
70
|
return "";
|
|
71
|
+
}
|
|
66
72
|
const r = req;
|
|
67
|
-
if (typeof r.locale === "string" && r.locale.length > 0)
|
|
73
|
+
if (typeof r.locale === "string" && r.locale.length > 0) {
|
|
74
|
+
console.log("[WWW] render/_locale:resolveLocale ->", r.locale, "(from req.locale)");
|
|
68
75
|
return r.locale;
|
|
76
|
+
}
|
|
69
77
|
const fallback = r.payload?.config?.localization?.defaultLocale;
|
|
70
|
-
if (typeof fallback === "string" && fallback.length > 0)
|
|
78
|
+
if (typeof fallback === "string" && fallback.length > 0) {
|
|
79
|
+
console.log("[WWW] render/_locale:resolveLocale ->", fallback, "(from config.localization.defaultLocale)");
|
|
71
80
|
return fallback;
|
|
81
|
+
}
|
|
82
|
+
console.log('[WWW] render/_locale:resolveLocale -> "" (no locale anywhere)');
|
|
72
83
|
return "";
|
|
73
84
|
}
|
|
74
85
|
function allLocales(req) {
|
|
75
|
-
if (!req || typeof req !== "object")
|
|
86
|
+
if (!req || typeof req !== "object") {
|
|
87
|
+
console.log("[WWW] render/_locale:allLocales -> [] (no req)");
|
|
76
88
|
return [];
|
|
89
|
+
}
|
|
77
90
|
const r = req;
|
|
78
91
|
const list = r.payload?.config?.localization?.locales;
|
|
79
|
-
if (!Array.isArray(list) || list.length === 0)
|
|
92
|
+
if (!Array.isArray(list) || list.length === 0) {
|
|
93
|
+
console.log("[WWW] render/_locale:allLocales -> [] (no locales declared)");
|
|
80
94
|
return [];
|
|
95
|
+
}
|
|
81
96
|
const out = [];
|
|
82
97
|
for (const entry of list) {
|
|
83
98
|
if (typeof entry === "string" && entry.length > 0) {
|
|
@@ -88,6 +103,7 @@ function allLocales(req) {
|
|
|
88
103
|
out.push(code);
|
|
89
104
|
}
|
|
90
105
|
}
|
|
106
|
+
console.log("[WWW] render/_locale:allLocales ->", JSON.stringify(out));
|
|
91
107
|
return out;
|
|
92
108
|
}
|
|
93
109
|
|
|
@@ -97,21 +113,28 @@ function nextCacheImport() {
|
|
|
97
113
|
return cachePromise ??= import("next/cache");
|
|
98
114
|
}
|
|
99
115
|
function shouldSkipRevalidate(context) {
|
|
100
|
-
|
|
116
|
+
const skip = Boolean(context?.disableRevalidate);
|
|
117
|
+
if (skip)
|
|
118
|
+
console.log("[WWW] render/hooks:_shared:shouldSkipRevalidate -> skip");
|
|
119
|
+
return skip;
|
|
101
120
|
}
|
|
102
121
|
async function safeRevalidatePath(payload, path) {
|
|
122
|
+
console.log("[WWW] render/hooks:_shared:safeRevalidatePath path=", path);
|
|
103
123
|
try {
|
|
104
124
|
const { revalidatePath } = await nextCacheImport();
|
|
105
125
|
revalidatePath(path);
|
|
106
126
|
} catch (error) {
|
|
127
|
+
console.error("[WWW] render/hooks:_shared:safeRevalidatePath failed path=", path, "err=", String(error));
|
|
107
128
|
payload.logger.error(`revalidatePath("${path}") failed: ${String(error)}`);
|
|
108
129
|
}
|
|
109
130
|
}
|
|
110
131
|
async function safeRevalidateTag(payload, tag, profile = "max") {
|
|
132
|
+
console.log("[WWW] render/hooks:_shared:safeRevalidateTag tag=", tag, "profile=", profile);
|
|
111
133
|
try {
|
|
112
134
|
const { revalidateTag } = await nextCacheImport();
|
|
113
135
|
revalidateTag(tag, profile);
|
|
114
136
|
} catch (error) {
|
|
137
|
+
console.error("[WWW] render/hooks:_shared:safeRevalidateTag failed tag=", tag, "err=", String(error));
|
|
115
138
|
payload.logger.error(`revalidateTag("${tag}") failed: ${String(error)}`);
|
|
116
139
|
}
|
|
117
140
|
}
|
|
@@ -127,6 +150,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
127
150
|
pathMode = "url"
|
|
128
151
|
} = options;
|
|
129
152
|
const resolvedSitemapTag = sitemapTag === false ? false : sitemapTag ?? `${collectionSlug}-sitemap`;
|
|
153
|
+
console.log("[WWW] render/hooks:createRevalidateCollectionHook collectionSlug=", collectionSlug, "urlPathPrefix=", urlPathPrefix, "sitemapTag=", resolvedSitemapTag, "pathMode=", pathMode);
|
|
130
154
|
const resolveDefaults = (req) => {
|
|
131
155
|
const mode = modeOption ?? "always";
|
|
132
156
|
const defaultLocale = defaultLocaleOption ?? req?.payload?.config?.localization?.defaultLocale ?? "";
|
|
@@ -155,6 +179,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
155
179
|
}
|
|
156
180
|
};
|
|
157
181
|
const fireCollectionTags = async (payload, docId, req) => {
|
|
182
|
+
console.log("[WWW] render/hooks:fireCollectionTags collectionSlug=", collectionSlug, "docId=", docId);
|
|
158
183
|
if (typeof docId === "string" || typeof docId === "number") {
|
|
159
184
|
await safeRevalidateTag(payload, `collection_${collectionSlug}_${docId}`);
|
|
160
185
|
}
|
|
@@ -168,6 +193,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
168
193
|
const { payload } = req;
|
|
169
194
|
const typed = doc;
|
|
170
195
|
const prev = previousDoc;
|
|
196
|
+
console.log("[WWW] render/hooks:afterChange collectionSlug=", collectionSlug, "id=", typed.id, "slug=", typed.slug, "prevSlug=", prev?.slug);
|
|
171
197
|
const isPublished = typed._status === "published";
|
|
172
198
|
const wasPublished = prev?._status === "published";
|
|
173
199
|
const prevSlugIsString = typeof prev?.slug === "string";
|
|
@@ -191,6 +217,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
191
217
|
return doc ?? null;
|
|
192
218
|
const { payload } = req;
|
|
193
219
|
const typed = doc;
|
|
220
|
+
console.log("[WWW] render/hooks:afterDelete collectionSlug=", collectionSlug, "id=", typed?.id, "slug=", typed?.slug);
|
|
194
221
|
if (pathMode !== "tag-only") {
|
|
195
222
|
await fanOutPaths(payload, req, typed?.slug, `Revalidating deleted ${collectionSlug} at path:`);
|
|
196
223
|
}
|
|
@@ -199,11 +226,14 @@ function createRevalidateCollectionHook(options) {
|
|
|
199
226
|
};
|
|
200
227
|
return { afterChange, afterDelete };
|
|
201
228
|
}
|
|
202
|
-
var createRevalidatePageHooks = (opts = {}) =>
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
229
|
+
var createRevalidatePageHooks = (opts = {}) => {
|
|
230
|
+
console.log("[WWW] render/hooks:createRevalidatePageHooks (deprecated alias) opts=", JSON.stringify(opts));
|
|
231
|
+
return createRevalidateCollectionHook({
|
|
232
|
+
collectionSlug: "pages",
|
|
233
|
+
urlPathPrefix: "",
|
|
234
|
+
...opts
|
|
235
|
+
});
|
|
236
|
+
};
|
|
207
237
|
|
|
208
238
|
// src/config/constants.ts
|
|
209
239
|
var PAGES_RENDER_PATH = "@justanarthur/payload-www/render-pages#PagesPage";
|
|
@@ -511,10 +541,12 @@ var link = (options = {}) => {
|
|
|
511
541
|
|
|
512
542
|
// src/render/hooks/revalidateGlobal.ts
|
|
513
543
|
function createRevalidateGlobalHook(slug) {
|
|
544
|
+
console.log("[WWW] render/hooks:createRevalidateGlobalHook slug=", slug);
|
|
514
545
|
return async ({ doc, req: { payload, context, locale } }) => {
|
|
515
546
|
if (shouldSkipRevalidate(context))
|
|
516
547
|
return doc;
|
|
517
548
|
const tags = [`global_${slug}`, `global_${slug}_${locale}`];
|
|
549
|
+
console.log("[WWW] render/hooks:revalidateGlobal slug=", slug, "locale=", locale, "tags=", JSON.stringify(tags));
|
|
518
550
|
payload.logger.info?.(`Revalidating global: ${tags.join(", ")}`);
|
|
519
551
|
for (const tag of tags) {
|
|
520
552
|
await safeRevalidateTag(payload, tag);
|
|
@@ -609,11 +641,14 @@ function createPreviewHandler(options) {
|
|
|
609
641
|
const url = new URL(req.url);
|
|
610
642
|
const path = url.searchParams.get("path") ?? "/";
|
|
611
643
|
const previewSecret = url.searchParams.get("previewSecret");
|
|
644
|
+
console.log("[WWW] render/preview:createPreviewHandler:GET path=", path, "hasSecret=", Boolean(previewSecret), "enableDraftMode=", enableDraftMode);
|
|
612
645
|
if (!previewSecret || previewSecret !== secret) {
|
|
646
|
+
console.warn("[WWW] render/preview:createPreviewHandler:GET invalid preview secret (401)");
|
|
613
647
|
return new Response("Invalid preview secret", { status: 401 });
|
|
614
648
|
}
|
|
615
649
|
if (enableDraftMode) {
|
|
616
650
|
(await draftMode()).enable();
|
|
651
|
+
console.log("[WWW] render/preview:createPreviewHandler:GET draftMode enabled");
|
|
617
652
|
}
|
|
618
653
|
redirect(path);
|
|
619
654
|
return new Response(null, { status: 204 });
|
|
@@ -633,6 +668,7 @@ async function buildHreflangAlternates({
|
|
|
633
668
|
localePrefix = "always"
|
|
634
669
|
}) {
|
|
635
670
|
const allLocaleSlugs = await queryAllLocaleSlugs(storedSlug, locale);
|
|
671
|
+
console.log("[WWW] render/metadata:buildHreflangAlternates storedSlug=", storedSlug, "locale=", locale, "allLocaleSlugs=", JSON.stringify(allLocaleSlugs));
|
|
636
672
|
const languages = {};
|
|
637
673
|
const urlFor = (l, slug) => {
|
|
638
674
|
const trimmedPrefix = urlPrefix.replace(/^\/|\/$/g, "");
|
|
@@ -650,6 +686,7 @@ async function buildHreflangAlternates({
|
|
|
650
686
|
if (allLocaleSlugs?.[defaultLocale]) {
|
|
651
687
|
languages["x-default"] = urlFor(defaultLocale, allLocaleSlugs[defaultLocale]);
|
|
652
688
|
}
|
|
689
|
+
console.log("[WWW] render/metadata:buildHreflangAlternates ->", JSON.stringify(languages));
|
|
653
690
|
return languages;
|
|
654
691
|
}
|
|
655
692
|
|
|
@@ -671,6 +708,7 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
|
|
|
671
708
|
draft = false,
|
|
672
709
|
config
|
|
673
710
|
}) {
|
|
711
|
+
console.log("[WWW] render/metadata:queryDocBySlug collection=", collectionSlug, "slug=", slug, "slugField=", slugField2, "locale=", locale, "draft=", draft);
|
|
674
712
|
const payload = await getPayload({ config });
|
|
675
713
|
const result = await payload.find({
|
|
676
714
|
collection: collectionSlug,
|
|
@@ -681,7 +719,9 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
|
|
|
681
719
|
where: { [slugField2]: { equals: slug } },
|
|
682
720
|
locale
|
|
683
721
|
});
|
|
684
|
-
|
|
722
|
+
const doc = result.docs?.[0] ?? null;
|
|
723
|
+
console.log("[WWW] render/metadata:queryDocBySlug ->", doc ? "hit" : "miss");
|
|
724
|
+
return doc;
|
|
685
725
|
});
|
|
686
726
|
var queryAllDocs = cache(async function queryAllDocs2({
|
|
687
727
|
collectionSlug,
|
|
@@ -689,6 +729,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
|
|
|
689
729
|
locale,
|
|
690
730
|
config
|
|
691
731
|
}) {
|
|
732
|
+
console.log("[WWW] render/metadata:queryAllDocs collection=", collectionSlug, "locale=", locale);
|
|
692
733
|
const payload = await getPayload({ config });
|
|
693
734
|
const result = await payload.find({
|
|
694
735
|
collection: collectionSlug,
|
|
@@ -699,7 +740,9 @@ var queryAllDocs = cache(async function queryAllDocs2({
|
|
|
699
740
|
select: { [slugField2]: true },
|
|
700
741
|
locale
|
|
701
742
|
});
|
|
702
|
-
|
|
743
|
+
const docs = result.docs ?? [];
|
|
744
|
+
console.log("[WWW] render/metadata:queryAllDocs -> count=", docs.length);
|
|
745
|
+
return docs;
|
|
703
746
|
});
|
|
704
747
|
var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
705
748
|
collectionSlug,
|
|
@@ -708,6 +751,7 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
|
708
751
|
locale,
|
|
709
752
|
config
|
|
710
753
|
}) {
|
|
754
|
+
console.log("[WWW] render/metadata:queryAllLocaleSlugs collection=", collectionSlug, "slug=", slug, "locale=", locale);
|
|
711
755
|
const payload = await getPayload({ config });
|
|
712
756
|
const result = await payload.find({
|
|
713
757
|
collection: collectionSlug,
|
|
@@ -720,8 +764,10 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
|
720
764
|
select: { [slugField2]: true }
|
|
721
765
|
});
|
|
722
766
|
const doc = result.docs?.[0];
|
|
723
|
-
if (!doc)
|
|
767
|
+
if (!doc) {
|
|
768
|
+
console.log("[WWW] render/metadata:queryAllLocaleSlugs -> undefined (no doc)");
|
|
724
769
|
return;
|
|
770
|
+
}
|
|
725
771
|
let fieldValue = doc[slugField2];
|
|
726
772
|
if (doc.id != null) {
|
|
727
773
|
const allLocales2 = await payload.findByID({
|
|
@@ -736,6 +782,7 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
|
736
782
|
fieldValue = allLocales2[slugField2];
|
|
737
783
|
}
|
|
738
784
|
if (fieldValue && typeof fieldValue === "object") {
|
|
785
|
+
console.log("[WWW] render/metadata:queryAllLocaleSlugs -> localized map=", JSON.stringify(fieldValue));
|
|
739
786
|
return fieldValue;
|
|
740
787
|
}
|
|
741
788
|
const resolved = await config;
|
|
@@ -743,6 +790,7 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
|
743
790
|
const out = {};
|
|
744
791
|
for (const l of rawLocales)
|
|
745
792
|
out[l] = String(fieldValue ?? slug);
|
|
793
|
+
console.log("[WWW] render/metadata:queryAllLocaleSlugs -> flat-fanout locales=", rawLocales.length, "slug=", JSON.stringify(fieldValue ?? slug));
|
|
746
794
|
return out;
|
|
747
795
|
});
|
|
748
796
|
var queryGlobal = cache(async function queryGlobal2({
|
|
@@ -752,6 +800,7 @@ var queryGlobal = cache(async function queryGlobal2({
|
|
|
752
800
|
draft = false,
|
|
753
801
|
config
|
|
754
802
|
}) {
|
|
803
|
+
console.log("[WWW] render/metadata:queryGlobal global=", globalSlug, "locale=", locale, "depth=", depth, "draft=", draft);
|
|
755
804
|
const payload = await getPayload({ config });
|
|
756
805
|
try {
|
|
757
806
|
const global = await payload.findGlobal({
|
|
@@ -760,27 +809,35 @@ var queryGlobal = cache(async function queryGlobal2({
|
|
|
760
809
|
draft,
|
|
761
810
|
locale
|
|
762
811
|
});
|
|
812
|
+
console.log("[WWW] render/metadata:queryGlobal -> hit");
|
|
763
813
|
return global;
|
|
764
|
-
} catch {
|
|
814
|
+
} catch (error) {
|
|
815
|
+
console.warn("[WWW] render/metadata:queryGlobal failed for slug=", globalSlug, "err=", String(error));
|
|
765
816
|
return null;
|
|
766
817
|
}
|
|
767
818
|
});
|
|
768
819
|
function getRenderModuleExports(exportName, collection, importMap) {
|
|
769
820
|
const path = collection?.custom?.path;
|
|
770
|
-
if (!path)
|
|
821
|
+
if (!path) {
|
|
822
|
+
console.log("[WWW] render/metadata:getRenderModuleExports no custom.path exportName=", exportName);
|
|
771
823
|
return;
|
|
824
|
+
}
|
|
772
825
|
const mod = getFromImportMap(path, importMap);
|
|
773
|
-
|
|
826
|
+
const value = mod?.[exportName];
|
|
827
|
+
console.log("[WWW] render/metadata:getRenderModuleExports exportName=", exportName, "path=", path, "hit=", Boolean(value));
|
|
828
|
+
return value;
|
|
774
829
|
}
|
|
775
830
|
|
|
776
831
|
// src/render/sitemap/createSitemapFile.ts
|
|
777
832
|
function createSitemapFile(options) {
|
|
778
833
|
const { collections } = options;
|
|
779
834
|
return async function sitemap() {
|
|
835
|
+
console.log("[WWW] render/sitemap:createSitemapFile:sitemap collections=", JSON.stringify(options.collections), "localePrefix=", options.localePrefix ?? "always");
|
|
780
836
|
const cfg = await options.config;
|
|
781
837
|
const allLocales2 = Array.isArray(cfg.localization?.locales) ? cfg.localization.locales.map((l) => typeof l === "string" ? l : l.code) : [cfg.localization?.defaultLocale ?? "en"];
|
|
782
838
|
const defaultLocale = cfg.localization?.defaultLocale ?? allLocales2[0];
|
|
783
839
|
const activeLocales = Array.isArray(options.locales) && options.locales.length > 0 ? options.locales.filter((l) => allLocales2.includes(l)) : allLocales2;
|
|
840
|
+
console.log("[WWW] render/sitemap:createSitemapFile:sitemap allLocales=", JSON.stringify(allLocales2), "default=", defaultLocale, "active=", JSON.stringify(activeLocales));
|
|
784
841
|
const entries = [];
|
|
785
842
|
const seen = new Set;
|
|
786
843
|
for (const collectionSlug of collections) {
|
|
@@ -836,6 +893,7 @@ function createSitemapFile(options) {
|
|
|
836
893
|
}
|
|
837
894
|
}
|
|
838
895
|
}
|
|
896
|
+
console.log("[WWW] render/sitemap:createSitemapFile:sitemap -> entries=", entries.length);
|
|
839
897
|
return entries;
|
|
840
898
|
};
|
|
841
899
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justanarthur/payload-www",
|
|
3
3
|
"description": "Reusable Payload CMS website template — config builder, collections, globals, blocks, fields, access, hooks, metadata (JSON-LD, hreflang), page renderers, and test helpers.",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"module": "./dist/index.js",
|