@justanarthur/payload-www 1.4.0 → 1.4.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.
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,32 @@ 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 : ""}${slug ? "/" + slug : ""}`;
330
+ })()}${prefix ? "/" + prefix : ""}${path ? "/" + path : ""}`;
325
331
  }
326
332
  function buildLocalizedPaths(localesSlug, pagePathPrefix, { routing }) {
333
+ if (!localesSlug[routing.defaultLocale])
334
+ return {};
327
335
  return routing.locales.reduce((paths, locale) => {
328
336
  const slug = localesSlug[locale];
337
+ if (!slug)
338
+ return paths;
329
339
  paths[locale] = buildLocalizedPath(locale, pagePathPrefix, slug, { routing });
330
340
  return paths;
331
341
  }, {});
332
342
  }
333
343
  function buildAlternates(locale, ...args) {
334
- const siteUrl = args[2].siteUrl;
335
- let localizedPaths = buildLocalizedPaths(...args);
336
- localizedPaths["x-default"] = localizedPaths[args[2].routing.defaultLocale];
337
- localizedPaths = Object.fromEntries(Object.entries(localizedPaths).map(([key, value]) => [key, siteUrl + localizedPaths[key]]));
344
+ const [localesSlug, pagePathPrefix, { routing, siteUrl }] = args;
345
+ const localizedPaths = buildLocalizedPaths(...args);
346
+ const defaultPath = localizedPaths[routing.defaultLocale];
347
+ if (defaultPath !== undefined)
348
+ localizedPaths["x-default"] = defaultPath;
349
+ const canonical = localizedPaths[locale] ?? buildLocalizedPath(locale, pagePathPrefix, localesSlug[locale], { routing });
338
350
  return {
339
- languages: localizedPaths,
340
- canonical: localizedPaths[locale]
351
+ languages: Object.fromEntries(Object.entries(localizedPaths).map(([key, value]) => [key, siteUrl + value])),
352
+ canonical: siteUrl + canonical
341
353
  };
342
354
  }
343
355
 
@@ -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,32 @@ 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 : ""}${slug ? "/" + slug : ""}`;
360
+ })()}${prefix ? "/" + prefix : ""}${path ? "/" + path : ""}`;
355
361
  }
356
362
  function buildLocalizedPaths(localesSlug, pagePathPrefix, { routing }) {
363
+ if (!localesSlug[routing.defaultLocale])
364
+ return {};
357
365
  return routing.locales.reduce((paths, locale) => {
358
366
  const slug = localesSlug[locale];
367
+ if (!slug)
368
+ return paths;
359
369
  paths[locale] = buildLocalizedPath(locale, pagePathPrefix, slug, { routing });
360
370
  return paths;
361
371
  }, {});
362
372
  }
363
373
  function buildAlternates(locale, ...args) {
364
- const siteUrl = args[2].siteUrl;
365
- let localizedPaths = buildLocalizedPaths(...args);
366
- localizedPaths["x-default"] = localizedPaths[args[2].routing.defaultLocale];
367
- localizedPaths = Object.fromEntries(Object.entries(localizedPaths).map(([key, value]) => [key, siteUrl + localizedPaths[key]]));
374
+ const [localesSlug, pagePathPrefix, { routing, siteUrl }] = args;
375
+ const localizedPaths = buildLocalizedPaths(...args);
376
+ const defaultPath = localizedPaths[routing.defaultLocale];
377
+ if (defaultPath !== undefined)
378
+ localizedPaths["x-default"] = defaultPath;
379
+ const canonical = localizedPaths[locale] ?? buildLocalizedPath(locale, pagePathPrefix, localesSlug[locale], { routing });
368
380
  return {
369
- languages: localizedPaths,
370
- canonical: localizedPaths[locale]
381
+ languages: Object.fromEntries(Object.entries(localizedPaths).map(([key, value]) => [key, siteUrl + value])),
382
+ canonical: siteUrl + canonical
371
383
  };
372
384
  }
373
385
 
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,32 @@ 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 : ""}${slug ? "/" + slug : ""}`;
153
+ })()}${prefix ? "/" + prefix : ""}${path ? "/" + path : ""}`;
148
154
  }
149
155
  function buildLocalizedPaths(localesSlug, pagePathPrefix, { routing }) {
156
+ if (!localesSlug[routing.defaultLocale])
157
+ return {};
150
158
  return routing.locales.reduce((paths, locale) => {
151
159
  const slug = localesSlug[locale];
160
+ if (!slug)
161
+ return paths;
152
162
  paths[locale] = buildLocalizedPath(locale, pagePathPrefix, slug, { routing });
153
163
  return paths;
154
164
  }, {});
155
165
  }
156
166
  function buildAlternates(locale, ...args) {
157
- const siteUrl = args[2].siteUrl;
158
- let localizedPaths = buildLocalizedPaths(...args);
159
- localizedPaths["x-default"] = localizedPaths[args[2].routing.defaultLocale];
160
- localizedPaths = Object.fromEntries(Object.entries(localizedPaths).map(([key, value]) => [key, siteUrl + localizedPaths[key]]));
167
+ const [localesSlug, pagePathPrefix, { routing, siteUrl }] = args;
168
+ const localizedPaths = buildLocalizedPaths(...args);
169
+ const defaultPath = localizedPaths[routing.defaultLocale];
170
+ if (defaultPath !== undefined)
171
+ localizedPaths["x-default"] = defaultPath;
172
+ const canonical = localizedPaths[locale] ?? buildLocalizedPath(locale, pagePathPrefix, localesSlug[locale], { routing });
161
173
  return {
162
- languages: localizedPaths,
163
- canonical: localizedPaths[locale]
174
+ languages: Object.fromEntries(Object.entries(localizedPaths).map(([key, value]) => [key, siteUrl + value])),
175
+ canonical: siteUrl + canonical
164
176
  };
165
177
  }
166
178
 
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.0",
4
+ "version": "1.4.1",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "files": [