@justanarthur/payload-www 0.3.2 → 0.3.4
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/access.js +13 -3
- package/dist/blocks.js +21 -7
- package/dist/collections.js +72 -19
- package/dist/components.js +1 -0
- package/dist/config.js +108 -26
- package/dist/core-access.js +13 -3
- package/dist/core-blocks.js +21 -7
- package/dist/core-fields.js +21 -7
- package/dist/core-utils.js +20 -6
- package/dist/data-collections.js +72 -19
- package/dist/data-test.js +108 -26
- package/dist/fields.js +21 -7
- package/dist/globals.js +18 -1
- package/dist/hooks.js +47 -15
- package/dist/index.js +1 -0
- package/dist/metadata.js +68 -22
- package/dist/pages.js +133 -39
- package/dist/render-components.js +13 -3
- package/dist/render-metadata.js +68 -22
- package/dist/render-pages.js +223 -59
- package/dist/render-utils.js +62 -16
- package/dist/server.js +245 -69
- package/dist/test.js +108 -26
- package/dist/utils.js +20 -6
- package/dist/with-www-config.js +108 -26
- package/package.json +1 -1
package/dist/globals.js
CHANGED
|
@@ -39,6 +39,13 @@ var link = (options = {}) => {
|
|
|
39
39
|
overrides = {},
|
|
40
40
|
extraFields = []
|
|
41
41
|
} = options;
|
|
42
|
+
console.log("[WWW] core/fields:link options=", JSON.stringify({
|
|
43
|
+
appearances: appearances === false ? false : appearances ?? "default-set",
|
|
44
|
+
disableLabel,
|
|
45
|
+
relationTo,
|
|
46
|
+
localized,
|
|
47
|
+
extraFieldsCount: extraFields.length
|
|
48
|
+
}));
|
|
42
49
|
const result = {
|
|
43
50
|
name: "link",
|
|
44
51
|
type: "group",
|
|
@@ -117,6 +124,7 @@ var link = (options = {}) => {
|
|
|
117
124
|
if (extraFields.length) {
|
|
118
125
|
result.fields.push(...extraFields);
|
|
119
126
|
}
|
|
127
|
+
console.log("[WWW] core/fields:link built fieldsCount=", result.fields.length);
|
|
120
128
|
return { ...result, ...overrides };
|
|
121
129
|
};
|
|
122
130
|
|
|
@@ -126,31 +134,40 @@ function nextCacheImport() {
|
|
|
126
134
|
return cachePromise ??= import("next/cache");
|
|
127
135
|
}
|
|
128
136
|
function shouldSkipRevalidate(context) {
|
|
129
|
-
|
|
137
|
+
const skip = Boolean(context?.disableRevalidate);
|
|
138
|
+
if (skip)
|
|
139
|
+
console.log("[WWW] render/hooks:_shared:shouldSkipRevalidate -> skip");
|
|
140
|
+
return skip;
|
|
130
141
|
}
|
|
131
142
|
async function safeRevalidatePath(payload, path) {
|
|
143
|
+
console.log("[WWW] render/hooks:_shared:safeRevalidatePath path=", path);
|
|
132
144
|
try {
|
|
133
145
|
const { revalidatePath } = await nextCacheImport();
|
|
134
146
|
revalidatePath(path);
|
|
135
147
|
} catch (error) {
|
|
148
|
+
console.error("[WWW] render/hooks:_shared:safeRevalidatePath failed path=", path, "err=", String(error));
|
|
136
149
|
payload.logger.error(`revalidatePath("${path}") failed: ${String(error)}`);
|
|
137
150
|
}
|
|
138
151
|
}
|
|
139
152
|
async function safeRevalidateTag(payload, tag, profile = "max") {
|
|
153
|
+
console.log("[WWW] render/hooks:_shared:safeRevalidateTag tag=", tag, "profile=", profile);
|
|
140
154
|
try {
|
|
141
155
|
const { revalidateTag } = await nextCacheImport();
|
|
142
156
|
revalidateTag(tag, profile);
|
|
143
157
|
} catch (error) {
|
|
158
|
+
console.error("[WWW] render/hooks:_shared:safeRevalidateTag failed tag=", tag, "err=", String(error));
|
|
144
159
|
payload.logger.error(`revalidateTag("${tag}") failed: ${String(error)}`);
|
|
145
160
|
}
|
|
146
161
|
}
|
|
147
162
|
|
|
148
163
|
// src/render/hooks/revalidateGlobal.ts
|
|
149
164
|
function createRevalidateGlobalHook(slug) {
|
|
165
|
+
console.log("[WWW] render/hooks:createRevalidateGlobalHook slug=", slug);
|
|
150
166
|
return async ({ doc, req: { payload, context, locale } }) => {
|
|
151
167
|
if (shouldSkipRevalidate(context))
|
|
152
168
|
return doc;
|
|
153
169
|
const tags = [`global_${slug}`, `global_${slug}_${locale}`];
|
|
170
|
+
console.log("[WWW] render/hooks:revalidateGlobal slug=", slug, "locale=", locale, "tags=", JSON.stringify(tags));
|
|
154
171
|
payload.logger.info?.(`Revalidating global: ${tags.join(", ")}`);
|
|
155
172
|
for (const tag of tags) {
|
|
156
173
|
await safeRevalidateTag(payload, tag);
|
package/dist/hooks.js
CHANGED
|
@@ -17,30 +17,45 @@ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
|
17
17
|
|
|
18
18
|
// src/render/_locale.ts
|
|
19
19
|
function prefixFor(locale, defaultLocale, mode) {
|
|
20
|
+
let result;
|
|
20
21
|
if (mode === "never")
|
|
21
|
-
|
|
22
|
-
if (mode === "as-needed" && locale === defaultLocale)
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
result = "";
|
|
23
|
+
else if (mode === "as-needed" && locale === defaultLocale)
|
|
24
|
+
result = "";
|
|
25
|
+
else
|
|
26
|
+
result = `/${locale}`;
|
|
27
|
+
console.log("[WWW] render/_locale:prefixFor locale=", locale, "default=", defaultLocale, "mode=", mode, "->", JSON.stringify(result));
|
|
28
|
+
return result;
|
|
25
29
|
}
|
|
26
30
|
function resolveLocale(req) {
|
|
27
|
-
if (!req || typeof req !== "object")
|
|
31
|
+
if (!req || typeof req !== "object") {
|
|
32
|
+
console.log('[WWW] render/_locale:resolveLocale -> "" (no req)');
|
|
28
33
|
return "";
|
|
34
|
+
}
|
|
29
35
|
const r = req;
|
|
30
|
-
if (typeof r.locale === "string" && r.locale.length > 0)
|
|
36
|
+
if (typeof r.locale === "string" && r.locale.length > 0) {
|
|
37
|
+
console.log("[WWW] render/_locale:resolveLocale ->", r.locale, "(from req.locale)");
|
|
31
38
|
return r.locale;
|
|
39
|
+
}
|
|
32
40
|
const fallback = r.payload?.config?.localization?.defaultLocale;
|
|
33
|
-
if (typeof fallback === "string" && fallback.length > 0)
|
|
41
|
+
if (typeof fallback === "string" && fallback.length > 0) {
|
|
42
|
+
console.log("[WWW] render/_locale:resolveLocale ->", fallback, "(from config.localization.defaultLocale)");
|
|
34
43
|
return fallback;
|
|
44
|
+
}
|
|
45
|
+
console.log('[WWW] render/_locale:resolveLocale -> "" (no locale anywhere)');
|
|
35
46
|
return "";
|
|
36
47
|
}
|
|
37
48
|
function allLocales(req) {
|
|
38
|
-
if (!req || typeof req !== "object")
|
|
49
|
+
if (!req || typeof req !== "object") {
|
|
50
|
+
console.log("[WWW] render/_locale:allLocales -> [] (no req)");
|
|
39
51
|
return [];
|
|
52
|
+
}
|
|
40
53
|
const r = req;
|
|
41
54
|
const list = r.payload?.config?.localization?.locales;
|
|
42
|
-
if (!Array.isArray(list) || list.length === 0)
|
|
55
|
+
if (!Array.isArray(list) || list.length === 0) {
|
|
56
|
+
console.log("[WWW] render/_locale:allLocales -> [] (no locales declared)");
|
|
43
57
|
return [];
|
|
58
|
+
}
|
|
44
59
|
const out = [];
|
|
45
60
|
for (const entry of list) {
|
|
46
61
|
if (typeof entry === "string" && entry.length > 0) {
|
|
@@ -51,6 +66,7 @@ function allLocales(req) {
|
|
|
51
66
|
out.push(code);
|
|
52
67
|
}
|
|
53
68
|
}
|
|
69
|
+
console.log("[WWW] render/_locale:allLocales ->", JSON.stringify(out));
|
|
54
70
|
return out;
|
|
55
71
|
}
|
|
56
72
|
|
|
@@ -60,21 +76,28 @@ function nextCacheImport() {
|
|
|
60
76
|
return cachePromise ??= import("next/cache");
|
|
61
77
|
}
|
|
62
78
|
function shouldSkipRevalidate(context) {
|
|
63
|
-
|
|
79
|
+
const skip = Boolean(context?.disableRevalidate);
|
|
80
|
+
if (skip)
|
|
81
|
+
console.log("[WWW] render/hooks:_shared:shouldSkipRevalidate -> skip");
|
|
82
|
+
return skip;
|
|
64
83
|
}
|
|
65
84
|
async function safeRevalidatePath(payload, path) {
|
|
85
|
+
console.log("[WWW] render/hooks:_shared:safeRevalidatePath path=", path);
|
|
66
86
|
try {
|
|
67
87
|
const { revalidatePath } = await nextCacheImport();
|
|
68
88
|
revalidatePath(path);
|
|
69
89
|
} catch (error) {
|
|
90
|
+
console.error("[WWW] render/hooks:_shared:safeRevalidatePath failed path=", path, "err=", String(error));
|
|
70
91
|
payload.logger.error(`revalidatePath("${path}") failed: ${String(error)}`);
|
|
71
92
|
}
|
|
72
93
|
}
|
|
73
94
|
async function safeRevalidateTag(payload, tag, profile = "max") {
|
|
95
|
+
console.log("[WWW] render/hooks:_shared:safeRevalidateTag tag=", tag, "profile=", profile);
|
|
74
96
|
try {
|
|
75
97
|
const { revalidateTag } = await nextCacheImport();
|
|
76
98
|
revalidateTag(tag, profile);
|
|
77
99
|
} catch (error) {
|
|
100
|
+
console.error("[WWW] render/hooks:_shared:safeRevalidateTag failed tag=", tag, "err=", String(error));
|
|
78
101
|
payload.logger.error(`revalidateTag("${tag}") failed: ${String(error)}`);
|
|
79
102
|
}
|
|
80
103
|
}
|
|
@@ -90,6 +113,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
90
113
|
pathMode = "url"
|
|
91
114
|
} = options;
|
|
92
115
|
const resolvedSitemapTag = sitemapTag === false ? false : sitemapTag ?? `${collectionSlug}-sitemap`;
|
|
116
|
+
console.log("[WWW] render/hooks:createRevalidateCollectionHook collectionSlug=", collectionSlug, "urlPathPrefix=", urlPathPrefix, "sitemapTag=", resolvedSitemapTag, "pathMode=", pathMode);
|
|
93
117
|
const resolveDefaults = (req) => {
|
|
94
118
|
const mode = modeOption ?? "always";
|
|
95
119
|
const defaultLocale = defaultLocaleOption ?? req?.payload?.config?.localization?.defaultLocale ?? "";
|
|
@@ -118,6 +142,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
118
142
|
}
|
|
119
143
|
};
|
|
120
144
|
const fireCollectionTags = async (payload, docId, req) => {
|
|
145
|
+
console.log("[WWW] render/hooks:fireCollectionTags collectionSlug=", collectionSlug, "docId=", docId);
|
|
121
146
|
if (typeof docId === "string" || typeof docId === "number") {
|
|
122
147
|
await safeRevalidateTag(payload, `collection_${collectionSlug}_${docId}`);
|
|
123
148
|
}
|
|
@@ -131,6 +156,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
131
156
|
const { payload } = req;
|
|
132
157
|
const typed = doc;
|
|
133
158
|
const prev = previousDoc;
|
|
159
|
+
console.log("[WWW] render/hooks:afterChange collectionSlug=", collectionSlug, "id=", typed.id, "slug=", typed.slug, "prevSlug=", prev?.slug);
|
|
134
160
|
const isPublished = typed._status === "published";
|
|
135
161
|
const wasPublished = prev?._status === "published";
|
|
136
162
|
const prevSlugIsString = typeof prev?.slug === "string";
|
|
@@ -154,6 +180,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
154
180
|
return doc ?? null;
|
|
155
181
|
const { payload } = req;
|
|
156
182
|
const typed = doc;
|
|
183
|
+
console.log("[WWW] render/hooks:afterDelete collectionSlug=", collectionSlug, "id=", typed?.id, "slug=", typed?.slug);
|
|
157
184
|
if (pathMode !== "tag-only") {
|
|
158
185
|
await fanOutPaths(payload, req, typed?.slug, `Revalidating deleted ${collectionSlug} at path:`);
|
|
159
186
|
}
|
|
@@ -162,18 +189,23 @@ function createRevalidateCollectionHook(options) {
|
|
|
162
189
|
};
|
|
163
190
|
return { afterChange, afterDelete };
|
|
164
191
|
}
|
|
165
|
-
var createRevalidatePageHooks = (opts = {}) =>
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
192
|
+
var createRevalidatePageHooks = (opts = {}) => {
|
|
193
|
+
console.log("[WWW] render/hooks:createRevalidatePageHooks (deprecated alias) opts=", JSON.stringify(opts));
|
|
194
|
+
return createRevalidateCollectionHook({
|
|
195
|
+
collectionSlug: "pages",
|
|
196
|
+
urlPathPrefix: "",
|
|
197
|
+
...opts
|
|
198
|
+
});
|
|
199
|
+
};
|
|
170
200
|
|
|
171
201
|
// src/render/hooks/revalidateGlobal.ts
|
|
172
202
|
function createRevalidateGlobalHook(slug) {
|
|
203
|
+
console.log("[WWW] render/hooks:createRevalidateGlobalHook slug=", slug);
|
|
173
204
|
return async ({ doc, req: { payload, context, locale } }) => {
|
|
174
205
|
if (shouldSkipRevalidate(context))
|
|
175
206
|
return doc;
|
|
176
207
|
const tags = [`global_${slug}`, `global_${slug}_${locale}`];
|
|
208
|
+
console.log("[WWW] render/hooks:revalidateGlobal slug=", slug, "locale=", locale, "tags=", JSON.stringify(tags));
|
|
177
209
|
payload.logger.info?.(`Revalidating global: ${tags.join(", ")}`);
|
|
178
210
|
for (const tag of tags) {
|
|
179
211
|
await safeRevalidateTag(payload, tag);
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
24
24
|
var LivePreviewListener = ({ serverURL }) => {
|
|
25
25
|
const router = useRouter();
|
|
26
26
|
const url = serverURL ?? process.env.NEXT_PUBLIC_SERVER_URL ?? (typeof window !== "undefined" ? window.location.origin : "");
|
|
27
|
+
console.log("[WWW] render/components:LivePreviewListener serverURL=", url);
|
|
27
28
|
return /* @__PURE__ */ jsx(PayloadLivePreview, {
|
|
28
29
|
refresh: router.refresh,
|
|
29
30
|
serverURL: url
|
package/dist/metadata.js
CHANGED
|
@@ -26,6 +26,11 @@ function getImageUrl(doc, siteUrl) {
|
|
|
26
26
|
return img.url.startsWith("http") ? img.url : `${siteUrl}${img.url}`;
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
|
+
function getImageUrlWithLog(doc, siteUrl) {
|
|
30
|
+
const result = getImageUrl(doc, siteUrl);
|
|
31
|
+
console.log("[WWW] render/metadata:jsonld:getImageUrl ->", result);
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
29
34
|
function resolveLocalizedField(value, locale) {
|
|
30
35
|
if (value == null)
|
|
31
36
|
return "";
|
|
@@ -47,6 +52,13 @@ function resolveLocalizedField(value, locale) {
|
|
|
47
52
|
}
|
|
48
53
|
return Object.values(obj).filter((v) => typeof v === "string" && v.length > 0).join(" / ");
|
|
49
54
|
}
|
|
55
|
+
function resolveLocalizedFieldWithLog(value, locale) {
|
|
56
|
+
const result = resolveLocalizedField(value, locale);
|
|
57
|
+
if (value && typeof value === "object") {
|
|
58
|
+
console.log("[WWW] render/metadata:jsonld:resolveLocalizedField locale=", locale, "->", JSON.stringify(result));
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
50
62
|
function buildArticleLd({
|
|
51
63
|
doc,
|
|
52
64
|
url,
|
|
@@ -57,12 +69,13 @@ function buildArticleLd({
|
|
|
57
69
|
publisherLogo
|
|
58
70
|
}) {
|
|
59
71
|
const name = publisherName ?? new URL(siteUrl).hostname;
|
|
72
|
+
console.log("[WWW] render/metadata:buildArticleLd url=", url, "locale=", locale, "type=", type, "publisherName=", name);
|
|
60
73
|
const ld = {
|
|
61
74
|
"@context": "https://schema.org",
|
|
62
75
|
"@type": type,
|
|
63
76
|
"@id": `${url}#article`,
|
|
64
|
-
headline:
|
|
65
|
-
description:
|
|
77
|
+
headline: resolveLocalizedFieldWithLog(doc.title, locale),
|
|
78
|
+
description: resolveLocalizedFieldWithLog(doc.meta?.description ?? doc.description ?? doc.excerpt, locale),
|
|
66
79
|
inLanguage: locale,
|
|
67
80
|
url,
|
|
68
81
|
dateModified: doc.updatedAt ? new Date(doc.updatedAt).toISOString() : undefined
|
|
@@ -70,7 +83,7 @@ function buildArticleLd({
|
|
|
70
83
|
const datePublished = doc.publishedAt ?? doc.createdAt;
|
|
71
84
|
if (datePublished)
|
|
72
85
|
ld.datePublished = new Date(datePublished).toISOString();
|
|
73
|
-
const imgUrl =
|
|
86
|
+
const imgUrl = getImageUrlWithLog(doc, siteUrl);
|
|
74
87
|
if (imgUrl)
|
|
75
88
|
ld.image = imgUrl;
|
|
76
89
|
ld.author = { "@type": "Organization", name, url: siteUrl };
|
|
@@ -86,6 +99,7 @@ function buildBreadcrumbsLd({
|
|
|
86
99
|
items,
|
|
87
100
|
currentUrl
|
|
88
101
|
}) {
|
|
102
|
+
console.log("[WWW] render/metadata:buildBreadcrumbsLd items=", items.length, "currentUrl=", currentUrl);
|
|
89
103
|
return {
|
|
90
104
|
"@context": "https://schema.org",
|
|
91
105
|
"@type": "BreadcrumbList",
|
|
@@ -103,6 +117,7 @@ function buildOrganizationLd({
|
|
|
103
117
|
logo,
|
|
104
118
|
sameAs
|
|
105
119
|
}) {
|
|
120
|
+
console.log("[WWW] render/metadata:buildOrganizationLd siteUrl=", siteUrl, "name=", name, "logo?", Boolean(logo), "sameAs?", Boolean(sameAs));
|
|
106
121
|
const org = {
|
|
107
122
|
"@context": "https://schema.org",
|
|
108
123
|
"@type": "Organization",
|
|
@@ -129,6 +144,7 @@ async function buildHreflangAlternates({
|
|
|
129
144
|
localePrefix = "always"
|
|
130
145
|
}) {
|
|
131
146
|
const allLocaleSlugs = await queryAllLocaleSlugs(storedSlug, locale);
|
|
147
|
+
console.log("[WWW] render/metadata:buildHreflangAlternates storedSlug=", storedSlug, "locale=", locale, "allLocaleSlugs=", JSON.stringify(allLocaleSlugs));
|
|
132
148
|
const languages = {};
|
|
133
149
|
const urlFor = (l, slug) => {
|
|
134
150
|
const trimmedPrefix = urlPrefix.replace(/^\/|\/$/g, "");
|
|
@@ -146,29 +162,36 @@ async function buildHreflangAlternates({
|
|
|
146
162
|
if (allLocaleSlugs?.[defaultLocale]) {
|
|
147
163
|
languages["x-default"] = urlFor(defaultLocale, allLocaleSlugs[defaultLocale]);
|
|
148
164
|
}
|
|
165
|
+
console.log("[WWW] render/metadata:buildHreflangAlternates ->", JSON.stringify(languages));
|
|
149
166
|
return languages;
|
|
150
167
|
}
|
|
151
168
|
|
|
152
169
|
// src/render/metadata/slug.ts
|
|
153
170
|
var SLUG_NESTED_DIVIDER = "_";
|
|
154
171
|
function segmentsToStoredSlug(segments, nested) {
|
|
155
|
-
if (!Array.isArray(segments))
|
|
172
|
+
if (!Array.isArray(segments)) {
|
|
173
|
+
console.log("[WWW] render/metadata:segmentsToStoredSlug string passthrough:", JSON.stringify(segments));
|
|
156
174
|
return segments;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
175
|
+
}
|
|
176
|
+
const result = nested ? segments.join(SLUG_NESTED_DIVIDER) : segments[0] ?? "";
|
|
177
|
+
console.log("[WWW] render/metadata:segmentsToStoredSlug nested=", nested, "segments=", JSON.stringify(segments), "->", result);
|
|
178
|
+
return result;
|
|
160
179
|
}
|
|
161
180
|
function segmentsToUrlPath(segments, nested) {
|
|
181
|
+
let result;
|
|
162
182
|
if (!Array.isArray(segments))
|
|
163
|
-
|
|
164
|
-
if (nested)
|
|
165
|
-
|
|
166
|
-
|
|
183
|
+
result = "/" + segments;
|
|
184
|
+
else if (nested)
|
|
185
|
+
result = "/" + segments.join("/");
|
|
186
|
+
else
|
|
187
|
+
result = "/" + (segments[0] ?? "");
|
|
188
|
+
console.log("[WWW] render/metadata:segmentsToUrlPath nested=", nested, "segments=", JSON.stringify(segments), "->", result);
|
|
189
|
+
return result;
|
|
167
190
|
}
|
|
168
191
|
function storedSlugToSegments(storedSlug, nested) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return
|
|
192
|
+
const result = nested ? storedSlug.split(SLUG_NESTED_DIVIDER) : storedSlug;
|
|
193
|
+
console.log("[WWW] render/metadata:storedSlugToSegments nested=", nested, "storedSlug=", storedSlug, "->", JSON.stringify(result));
|
|
194
|
+
return result;
|
|
172
195
|
}
|
|
173
196
|
function buildCanonicalUrl({
|
|
174
197
|
siteUrl,
|
|
@@ -178,7 +201,9 @@ function buildCanonicalUrl({
|
|
|
178
201
|
}) {
|
|
179
202
|
const trimmedPrefix = urlPrefix.replace(/^\/|\/$/g, "");
|
|
180
203
|
const prefixSegment = trimmedPrefix ? `/${trimmedPrefix}` : "";
|
|
181
|
-
|
|
204
|
+
const result = `${siteUrl}/${locale}${prefixSegment}${urlPath}`;
|
|
205
|
+
console.log("[WWW] render/metadata:buildCanonicalUrl siteUrl=", siteUrl, "locale=", locale, "urlPrefix=", urlPrefix, "urlPath=", urlPath, "->", result);
|
|
206
|
+
return result;
|
|
182
207
|
}
|
|
183
208
|
function getUrlPath(segments, nested, homeSlug) {
|
|
184
209
|
const urlPath = segmentsToUrlPath(segments, nested);
|
|
@@ -199,7 +224,10 @@ import { cache } from "react";
|
|
|
199
224
|
|
|
200
225
|
// src/core/utils/getFromImportMap.ts
|
|
201
226
|
function getFromImportMap(key, importMap) {
|
|
202
|
-
|
|
227
|
+
const resolvedKey = key.includes("#") ? key : key + "#default";
|
|
228
|
+
const value = importMap[resolvedKey];
|
|
229
|
+
console.log("[WWW] core/utils:getFromImportMap key=", key, "resolved=", resolvedKey, "hit=", Boolean(value));
|
|
230
|
+
return value;
|
|
203
231
|
}
|
|
204
232
|
|
|
205
233
|
// src/render/metadata/query.ts
|
|
@@ -211,6 +239,7 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
|
|
|
211
239
|
draft = false,
|
|
212
240
|
config
|
|
213
241
|
}) {
|
|
242
|
+
console.log("[WWW] render/metadata:queryDocBySlug collection=", collectionSlug, "slug=", slug, "slugField=", slugField, "locale=", locale, "draft=", draft);
|
|
214
243
|
const payload = await getPayload({ config });
|
|
215
244
|
const result = await payload.find({
|
|
216
245
|
collection: collectionSlug,
|
|
@@ -221,7 +250,9 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
|
|
|
221
250
|
where: { [slugField]: { equals: slug } },
|
|
222
251
|
locale
|
|
223
252
|
});
|
|
224
|
-
|
|
253
|
+
const doc = result.docs?.[0] ?? null;
|
|
254
|
+
console.log("[WWW] render/metadata:queryDocBySlug ->", doc ? "hit" : "miss");
|
|
255
|
+
return doc;
|
|
225
256
|
});
|
|
226
257
|
var queryAllDocs = cache(async function queryAllDocs2({
|
|
227
258
|
collectionSlug,
|
|
@@ -229,6 +260,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
|
|
|
229
260
|
locale,
|
|
230
261
|
config
|
|
231
262
|
}) {
|
|
263
|
+
console.log("[WWW] render/metadata:queryAllDocs collection=", collectionSlug, "locale=", locale);
|
|
232
264
|
const payload = await getPayload({ config });
|
|
233
265
|
const result = await payload.find({
|
|
234
266
|
collection: collectionSlug,
|
|
@@ -239,7 +271,9 @@ var queryAllDocs = cache(async function queryAllDocs2({
|
|
|
239
271
|
select: { [slugField]: true },
|
|
240
272
|
locale
|
|
241
273
|
});
|
|
242
|
-
|
|
274
|
+
const docs = result.docs ?? [];
|
|
275
|
+
console.log("[WWW] render/metadata:queryAllDocs -> count=", docs.length);
|
|
276
|
+
return docs;
|
|
243
277
|
});
|
|
244
278
|
var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
245
279
|
collectionSlug,
|
|
@@ -248,6 +282,7 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
|
248
282
|
locale,
|
|
249
283
|
config
|
|
250
284
|
}) {
|
|
285
|
+
console.log("[WWW] render/metadata:queryAllLocaleSlugs collection=", collectionSlug, "slug=", slug, "locale=", locale);
|
|
251
286
|
const payload = await getPayload({ config });
|
|
252
287
|
const result = await payload.find({
|
|
253
288
|
collection: collectionSlug,
|
|
@@ -260,8 +295,10 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
|
260
295
|
select: { [slugField]: true }
|
|
261
296
|
});
|
|
262
297
|
const doc = result.docs?.[0];
|
|
263
|
-
if (!doc)
|
|
298
|
+
if (!doc) {
|
|
299
|
+
console.log("[WWW] render/metadata:queryAllLocaleSlugs -> undefined (no doc)");
|
|
264
300
|
return;
|
|
301
|
+
}
|
|
265
302
|
let fieldValue = doc[slugField];
|
|
266
303
|
if (doc.id != null) {
|
|
267
304
|
const allLocales = await payload.findByID({
|
|
@@ -276,6 +313,7 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
|
276
313
|
fieldValue = allLocales[slugField];
|
|
277
314
|
}
|
|
278
315
|
if (fieldValue && typeof fieldValue === "object") {
|
|
316
|
+
console.log("[WWW] render/metadata:queryAllLocaleSlugs -> localized map=", JSON.stringify(fieldValue));
|
|
279
317
|
return fieldValue;
|
|
280
318
|
}
|
|
281
319
|
const resolved = await config;
|
|
@@ -283,6 +321,7 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
|
|
|
283
321
|
const out = {};
|
|
284
322
|
for (const l of rawLocales)
|
|
285
323
|
out[l] = String(fieldValue ?? slug);
|
|
324
|
+
console.log("[WWW] render/metadata:queryAllLocaleSlugs -> flat-fanout locales=", rawLocales.length, "slug=", JSON.stringify(fieldValue ?? slug));
|
|
286
325
|
return out;
|
|
287
326
|
});
|
|
288
327
|
var queryGlobal = cache(async function queryGlobal2({
|
|
@@ -292,6 +331,7 @@ var queryGlobal = cache(async function queryGlobal2({
|
|
|
292
331
|
draft = false,
|
|
293
332
|
config
|
|
294
333
|
}) {
|
|
334
|
+
console.log("[WWW] render/metadata:queryGlobal global=", globalSlug, "locale=", locale, "depth=", depth, "draft=", draft);
|
|
295
335
|
const payload = await getPayload({ config });
|
|
296
336
|
try {
|
|
297
337
|
const global = await payload.findGlobal({
|
|
@@ -300,17 +340,23 @@ var queryGlobal = cache(async function queryGlobal2({
|
|
|
300
340
|
draft,
|
|
301
341
|
locale
|
|
302
342
|
});
|
|
343
|
+
console.log("[WWW] render/metadata:queryGlobal -> hit");
|
|
303
344
|
return global;
|
|
304
|
-
} catch {
|
|
345
|
+
} catch (error) {
|
|
346
|
+
console.warn("[WWW] render/metadata:queryGlobal failed for slug=", globalSlug, "err=", String(error));
|
|
305
347
|
return null;
|
|
306
348
|
}
|
|
307
349
|
});
|
|
308
350
|
function getRenderModuleExports(exportName, collection, importMap) {
|
|
309
351
|
const path = collection?.custom?.path;
|
|
310
|
-
if (!path)
|
|
352
|
+
if (!path) {
|
|
353
|
+
console.log("[WWW] render/metadata:getRenderModuleExports no custom.path exportName=", exportName);
|
|
311
354
|
return;
|
|
355
|
+
}
|
|
312
356
|
const mod = getFromImportMap(path, importMap);
|
|
313
|
-
|
|
357
|
+
const value = mod?.[exportName];
|
|
358
|
+
console.log("[WWW] render/metadata:getRenderModuleExports exportName=", exportName, "path=", path, "hit=", Boolean(value));
|
|
359
|
+
return value;
|
|
314
360
|
}
|
|
315
361
|
|
|
316
362
|
// src/exports/metadata.ts
|