@justanarthur/payload-www 1.4.0 → 1.4.2
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/metadata.js +5 -0
- package/dist/pages.js +18 -7
- package/dist/render-pages.js +18 -7
- package/dist/sitemap.js +18 -7
- package/package.json +1 -1
package/dist/metadata.js
CHANGED
|
@@ -105,6 +105,11 @@ function slugToParamsSlug(slug, shape) {
|
|
|
105
105
|
return shape === "catch-all" ? [] : "";
|
|
106
106
|
return shape === "catch-all" ? slug.split(SLUG_NESTED_DIVIDER) : slug;
|
|
107
107
|
}
|
|
108
|
+
function slugToPath(slug) {
|
|
109
|
+
if (!slug)
|
|
110
|
+
return "";
|
|
111
|
+
return slug.split(SLUG_NESTED_DIVIDER).join("/");
|
|
112
|
+
}
|
|
108
113
|
|
|
109
114
|
// src/render/metadata/query.ts
|
|
110
115
|
import { getPayload } from "payload";
|
package/dist/pages.js
CHANGED
|
@@ -192,6 +192,11 @@ function slugToParamsSlug(slug, shape) {
|
|
|
192
192
|
return shape === "catch-all" ? [] : "";
|
|
193
193
|
return shape === "catch-all" ? slug.split(SLUG_NESTED_DIVIDER) : slug;
|
|
194
194
|
}
|
|
195
|
+
function slugToPath(slug) {
|
|
196
|
+
if (!slug)
|
|
197
|
+
return "";
|
|
198
|
+
return slug.split(SLUG_NESTED_DIVIDER).join("/");
|
|
199
|
+
}
|
|
195
200
|
|
|
196
201
|
// src/render/metadata/query.ts
|
|
197
202
|
import { getPayload } from "payload";
|
|
@@ -319,25 +324,31 @@ import { setRequestLocale } from "next-intl/server";
|
|
|
319
324
|
|
|
320
325
|
// src/render/pages/utils/buildLocalizedPath.ts
|
|
321
326
|
function buildLocalizedPath(locale, prefix, slug, { routing }) {
|
|
327
|
+
const path = slugToPath(slug);
|
|
322
328
|
return `${routing.localePrefix === "never" ? "" : routing.localePrefix === "always" ? locale : routing.localePrefix === "as-needed" ? locale === routing.defaultLocale ? "" : "/" + locale : (() => {
|
|
323
329
|
throw new Error("Unsupported locale prefix");
|
|
324
|
-
})()}${prefix ? "/" + prefix : ""}${
|
|
330
|
+
})()}${prefix ? "/" + prefix : ""}${path ? "/" + path : ""}`;
|
|
325
331
|
}
|
|
326
332
|
function buildLocalizedPaths(localesSlug, pagePathPrefix, { routing }) {
|
|
333
|
+
const blankIsHome = !localesSlug[routing.defaultLocale];
|
|
327
334
|
return routing.locales.reduce((paths, locale) => {
|
|
328
335
|
const slug = localesSlug[locale];
|
|
336
|
+
if (!slug && !blankIsHome)
|
|
337
|
+
return paths;
|
|
329
338
|
paths[locale] = buildLocalizedPath(locale, pagePathPrefix, slug, { routing });
|
|
330
339
|
return paths;
|
|
331
340
|
}, {});
|
|
332
341
|
}
|
|
333
342
|
function buildAlternates(locale, ...args) {
|
|
334
|
-
const siteUrl = args
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
343
|
+
const [localesSlug, pagePathPrefix, { routing, siteUrl }] = args;
|
|
344
|
+
const localizedPaths = buildLocalizedPaths(...args);
|
|
345
|
+
const defaultPath = localizedPaths[routing.defaultLocale];
|
|
346
|
+
if (defaultPath !== undefined)
|
|
347
|
+
localizedPaths["x-default"] = defaultPath;
|
|
348
|
+
const canonical = localizedPaths[locale] ?? buildLocalizedPath(locale, pagePathPrefix, localesSlug[locale], { routing });
|
|
338
349
|
return {
|
|
339
|
-
languages: localizedPaths,
|
|
340
|
-
canonical:
|
|
350
|
+
languages: Object.fromEntries(Object.entries(localizedPaths).map(([key, value]) => [key, siteUrl + value])),
|
|
351
|
+
canonical: siteUrl + canonical
|
|
341
352
|
};
|
|
342
353
|
}
|
|
343
354
|
|
package/dist/render-pages.js
CHANGED
|
@@ -222,6 +222,11 @@ function slugToParamsSlug(slug, shape) {
|
|
|
222
222
|
return shape === "catch-all" ? [] : "";
|
|
223
223
|
return shape === "catch-all" ? slug.split(SLUG_NESTED_DIVIDER) : slug;
|
|
224
224
|
}
|
|
225
|
+
function slugToPath(slug) {
|
|
226
|
+
if (!slug)
|
|
227
|
+
return "";
|
|
228
|
+
return slug.split(SLUG_NESTED_DIVIDER).join("/");
|
|
229
|
+
}
|
|
225
230
|
|
|
226
231
|
// src/render/metadata/query.ts
|
|
227
232
|
import { getPayload } from "payload";
|
|
@@ -349,25 +354,31 @@ import { setRequestLocale } from "next-intl/server";
|
|
|
349
354
|
|
|
350
355
|
// src/render/pages/utils/buildLocalizedPath.ts
|
|
351
356
|
function buildLocalizedPath(locale, prefix, slug, { routing }) {
|
|
357
|
+
const path = slugToPath(slug);
|
|
352
358
|
return `${routing.localePrefix === "never" ? "" : routing.localePrefix === "always" ? locale : routing.localePrefix === "as-needed" ? locale === routing.defaultLocale ? "" : "/" + locale : (() => {
|
|
353
359
|
throw new Error("Unsupported locale prefix");
|
|
354
|
-
})()}${prefix ? "/" + prefix : ""}${
|
|
360
|
+
})()}${prefix ? "/" + prefix : ""}${path ? "/" + path : ""}`;
|
|
355
361
|
}
|
|
356
362
|
function buildLocalizedPaths(localesSlug, pagePathPrefix, { routing }) {
|
|
363
|
+
const blankIsHome = !localesSlug[routing.defaultLocale];
|
|
357
364
|
return routing.locales.reduce((paths, locale) => {
|
|
358
365
|
const slug = localesSlug[locale];
|
|
366
|
+
if (!slug && !blankIsHome)
|
|
367
|
+
return paths;
|
|
359
368
|
paths[locale] = buildLocalizedPath(locale, pagePathPrefix, slug, { routing });
|
|
360
369
|
return paths;
|
|
361
370
|
}, {});
|
|
362
371
|
}
|
|
363
372
|
function buildAlternates(locale, ...args) {
|
|
364
|
-
const siteUrl = args
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
373
|
+
const [localesSlug, pagePathPrefix, { routing, siteUrl }] = args;
|
|
374
|
+
const localizedPaths = buildLocalizedPaths(...args);
|
|
375
|
+
const defaultPath = localizedPaths[routing.defaultLocale];
|
|
376
|
+
if (defaultPath !== undefined)
|
|
377
|
+
localizedPaths["x-default"] = defaultPath;
|
|
378
|
+
const canonical = localizedPaths[locale] ?? buildLocalizedPath(locale, pagePathPrefix, localesSlug[locale], { routing });
|
|
368
379
|
return {
|
|
369
|
-
languages: localizedPaths,
|
|
370
|
-
canonical:
|
|
380
|
+
languages: Object.fromEntries(Object.entries(localizedPaths).map(([key, value]) => [key, siteUrl + value])),
|
|
381
|
+
canonical: siteUrl + canonical
|
|
371
382
|
};
|
|
372
383
|
}
|
|
373
384
|
|
package/dist/sitemap.js
CHANGED
|
@@ -15,6 +15,11 @@ function slugToParamsSlug(slug, shape) {
|
|
|
15
15
|
return shape === "catch-all" ? [] : "";
|
|
16
16
|
return shape === "catch-all" ? slug.split(SLUG_NESTED_DIVIDER) : slug;
|
|
17
17
|
}
|
|
18
|
+
function slugToPath(slug) {
|
|
19
|
+
if (!slug)
|
|
20
|
+
return "";
|
|
21
|
+
return slug.split(SLUG_NESTED_DIVIDER).join("/");
|
|
22
|
+
}
|
|
18
23
|
|
|
19
24
|
// src/render/metadata/query.ts
|
|
20
25
|
import { getPayload } from "payload";
|
|
@@ -142,25 +147,31 @@ import { setRequestLocale } from "next-intl/server";
|
|
|
142
147
|
|
|
143
148
|
// src/render/pages/utils/buildLocalizedPath.ts
|
|
144
149
|
function buildLocalizedPath(locale, prefix, slug, { routing }) {
|
|
150
|
+
const path = slugToPath(slug);
|
|
145
151
|
return `${routing.localePrefix === "never" ? "" : routing.localePrefix === "always" ? locale : routing.localePrefix === "as-needed" ? locale === routing.defaultLocale ? "" : "/" + locale : (() => {
|
|
146
152
|
throw new Error("Unsupported locale prefix");
|
|
147
|
-
})()}${prefix ? "/" + prefix : ""}${
|
|
153
|
+
})()}${prefix ? "/" + prefix : ""}${path ? "/" + path : ""}`;
|
|
148
154
|
}
|
|
149
155
|
function buildLocalizedPaths(localesSlug, pagePathPrefix, { routing }) {
|
|
156
|
+
const blankIsHome = !localesSlug[routing.defaultLocale];
|
|
150
157
|
return routing.locales.reduce((paths, locale) => {
|
|
151
158
|
const slug = localesSlug[locale];
|
|
159
|
+
if (!slug && !blankIsHome)
|
|
160
|
+
return paths;
|
|
152
161
|
paths[locale] = buildLocalizedPath(locale, pagePathPrefix, slug, { routing });
|
|
153
162
|
return paths;
|
|
154
163
|
}, {});
|
|
155
164
|
}
|
|
156
165
|
function buildAlternates(locale, ...args) {
|
|
157
|
-
const siteUrl = args
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
166
|
+
const [localesSlug, pagePathPrefix, { routing, siteUrl }] = args;
|
|
167
|
+
const localizedPaths = buildLocalizedPaths(...args);
|
|
168
|
+
const defaultPath = localizedPaths[routing.defaultLocale];
|
|
169
|
+
if (defaultPath !== undefined)
|
|
170
|
+
localizedPaths["x-default"] = defaultPath;
|
|
171
|
+
const canonical = localizedPaths[locale] ?? buildLocalizedPath(locale, pagePathPrefix, localesSlug[locale], { routing });
|
|
161
172
|
return {
|
|
162
|
-
languages: localizedPaths,
|
|
163
|
-
canonical:
|
|
173
|
+
languages: Object.fromEntries(Object.entries(localizedPaths).map(([key, value]) => [key, siteUrl + value])),
|
|
174
|
+
canonical: siteUrl + canonical
|
|
164
175
|
};
|
|
165
176
|
}
|
|
166
177
|
|
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": "1.4.
|
|
4
|
+
"version": "1.4.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"files": [
|