@justanarthur/payload-www 0.2.0 → 0.3.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.
@@ -24,6 +24,34 @@ var authenticatedOrPublished = ({ req: { user } }) => {
24
24
  return { _status: { equals: "published" } };
25
25
  };
26
26
 
27
+ // src/core/fields/slug.ts
28
+ var FLAT_PATTERN = /^[a-z0-9-]+$/;
29
+ var NESTED_PATTERN = /^[a-z0-9_-]+$/;
30
+ var slugField = (options = {}) => {
31
+ const { name = "slug", nested = false, localized = true } = options;
32
+ const pattern = nested ? NESTED_PATTERN : FLAT_PATTERN;
33
+ const invalidMessage = nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
34
+ return {
35
+ name,
36
+ type: "text",
37
+ required: true,
38
+ unique: true,
39
+ index: true,
40
+ localized,
41
+ admin: {
42
+ position: "sidebar",
43
+ ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
44
+ },
45
+ validate: (value) => {
46
+ if (typeof value !== "string")
47
+ return "Slug must be a string";
48
+ if (value !== "" && !pattern.test(value))
49
+ return invalidMessage;
50
+ return true;
51
+ }
52
+ };
53
+ };
54
+
27
55
  // src/render/_locale.ts
28
56
  function prefixFor(locale, defaultLocale, mode) {
29
57
  if (mode === "never")
@@ -198,26 +226,6 @@ var createPagesCollection = (blocks, options = {}) => {
198
226
  defaultLocale,
199
227
  nested = false
200
228
  } = options;
201
- const slugPattern = nested ? /^[a-z0-9_-]+$/ : /^[a-z0-9-]+$/;
202
- const slugField = {
203
- name: "slug",
204
- type: "text",
205
- required: true,
206
- unique: true,
207
- index: true,
208
- admin: {
209
- position: "sidebar",
210
- ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
211
- },
212
- validate: (value) => {
213
- if (typeof value !== "string")
214
- return "Slug must be a string";
215
- if (value !== "" && !slugPattern.test(value)) {
216
- return nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
217
- }
218
- return true;
219
- }
220
- };
221
229
  const baseFields = [
222
230
  {
223
231
  name: "title",
@@ -247,7 +255,7 @@ var createPagesCollection = (blocks, options = {}) => {
247
255
  type: "date",
248
256
  admin: { position: "sidebar" }
249
257
  },
250
- slugField
258
+ slugField({ nested })
251
259
  ];
252
260
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
253
261
  collectionSlug,
@@ -282,14 +290,6 @@ var createPostsCollection = (options = {}) => {
282
290
  localePrefix,
283
291
  defaultLocale
284
292
  } = options;
285
- const slugField = {
286
- name: "slug",
287
- type: "text",
288
- required: true,
289
- unique: true,
290
- index: true,
291
- admin: { position: "sidebar" }
292
- };
293
293
  const baseFields = [
294
294
  {
295
295
  name: "title",
@@ -314,7 +314,7 @@ var createPostsCollection = (options = {}) => {
314
314
  type: "date",
315
315
  admin: { position: "sidebar" }
316
316
  },
317
- slugField
317
+ slugField()
318
318
  ];
319
319
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
320
320
  collectionSlug,
package/dist/config.js CHANGED
@@ -24,6 +24,34 @@ var authenticatedOrPublished = ({ req: { user } }) => {
24
24
  return { _status: { equals: "published" } };
25
25
  };
26
26
 
27
+ // src/core/fields/slug.ts
28
+ var FLAT_PATTERN = /^[a-z0-9-]+$/;
29
+ var NESTED_PATTERN = /^[a-z0-9_-]+$/;
30
+ var slugField = (options = {}) => {
31
+ const { name = "slug", nested = false, localized = true } = options;
32
+ const pattern = nested ? NESTED_PATTERN : FLAT_PATTERN;
33
+ const invalidMessage = nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
34
+ return {
35
+ name,
36
+ type: "text",
37
+ required: true,
38
+ unique: true,
39
+ index: true,
40
+ localized,
41
+ admin: {
42
+ position: "sidebar",
43
+ ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
44
+ },
45
+ validate: (value) => {
46
+ if (typeof value !== "string")
47
+ return "Slug must be a string";
48
+ if (value !== "" && !pattern.test(value))
49
+ return invalidMessage;
50
+ return true;
51
+ }
52
+ };
53
+ };
54
+
27
55
  // src/render/_locale.ts
28
56
  function prefixFor(locale, defaultLocale, mode) {
29
57
  if (mode === "never")
@@ -198,26 +226,6 @@ var createPagesCollection = (blocks, options = {}) => {
198
226
  defaultLocale,
199
227
  nested = false
200
228
  } = options;
201
- const slugPattern = nested ? /^[a-z0-9_-]+$/ : /^[a-z0-9-]+$/;
202
- const slugField = {
203
- name: "slug",
204
- type: "text",
205
- required: true,
206
- unique: true,
207
- index: true,
208
- admin: {
209
- position: "sidebar",
210
- ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
211
- },
212
- validate: (value) => {
213
- if (typeof value !== "string")
214
- return "Slug must be a string";
215
- if (value !== "" && !slugPattern.test(value)) {
216
- return nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
217
- }
218
- return true;
219
- }
220
- };
221
229
  const baseFields = [
222
230
  {
223
231
  name: "title",
@@ -247,7 +255,7 @@ var createPagesCollection = (blocks, options = {}) => {
247
255
  type: "date",
248
256
  admin: { position: "sidebar" }
249
257
  },
250
- slugField
258
+ slugField({ nested })
251
259
  ];
252
260
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
253
261
  collectionSlug,
@@ -282,14 +290,6 @@ var createPostsCollection = (options = {}) => {
282
290
  localePrefix,
283
291
  defaultLocale
284
292
  } = options;
285
- const slugField = {
286
- name: "slug",
287
- type: "text",
288
- required: true,
289
- unique: true,
290
- index: true,
291
- admin: { position: "sidebar" }
292
- };
293
293
  const baseFields = [
294
294
  {
295
295
  name: "title",
@@ -314,7 +314,7 @@ var createPostsCollection = (options = {}) => {
314
314
  type: "date",
315
315
  admin: { position: "sidebar" }
316
316
  },
317
- slugField
317
+ slugField()
318
318
  ];
319
319
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
320
320
  collectionSlug,
@@ -666,7 +666,7 @@ function getFromImportMap(key, importMap) {
666
666
  var queryDocBySlug = cache(async function queryDocBySlug2({
667
667
  collectionSlug,
668
668
  slug,
669
- slugField = "slug",
669
+ slugField: slugField2 = "slug",
670
670
  locale,
671
671
  draft = false,
672
672
  config
@@ -678,14 +678,14 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
678
678
  limit: 1,
679
679
  pagination: false,
680
680
  overrideAccess: draft,
681
- where: { [slugField]: { equals: slug } },
681
+ where: { [slugField2]: { equals: slug } },
682
682
  locale
683
683
  });
684
684
  return result.docs?.[0] ?? null;
685
685
  });
686
686
  var queryAllDocs = cache(async function queryAllDocs2({
687
687
  collectionSlug,
688
- slugField = "slug",
688
+ slugField: slugField2 = "slug",
689
689
  locale,
690
690
  config
691
691
  }) {
@@ -696,7 +696,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
696
696
  limit: 1000,
697
697
  pagination: false,
698
698
  overrideAccess: false,
699
- select: { [slugField]: true },
699
+ select: { [slugField2]: true },
700
700
  locale
701
701
  });
702
702
  return result.docs ?? [];
@@ -704,7 +704,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
704
704
  var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
705
705
  collectionSlug,
706
706
  slug,
707
- slugField = "slug",
707
+ slugField: slugField2 = "slug",
708
708
  locale,
709
709
  config
710
710
  }) {
@@ -716,13 +716,25 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
716
716
  pagination: false,
717
717
  overrideAccess: false,
718
718
  locale,
719
- where: { [slugField]: { equals: slug } },
720
- select: { [slugField]: true }
719
+ where: { [slugField2]: { equals: slug } },
720
+ select: { [slugField2]: true }
721
721
  });
722
722
  const doc = result.docs?.[0];
723
723
  if (!doc)
724
724
  return;
725
- const fieldValue = doc?.[slugField];
725
+ let fieldValue = doc[slugField2];
726
+ if (doc.id != null) {
727
+ const allLocales2 = await payload.findByID({
728
+ collection: collectionSlug,
729
+ id: doc.id,
730
+ locale: "all",
731
+ draft: false,
732
+ overrideAccess: false,
733
+ select: { [slugField2]: true }
734
+ }).catch(() => null);
735
+ if (allLocales2)
736
+ fieldValue = allLocales2[slugField2];
737
+ }
726
738
  if (fieldValue && typeof fieldValue === "object") {
727
739
  return fieldValue;
728
740
  }
@@ -32,6 +32,34 @@ type LinkOptions = {
32
32
  declare const link: (options?: LinkOptions) => Field;
33
33
  import { Field as Field2 } from "payload";
34
34
  declare const linkGroup: (options?: LinkOptions) => Field2;
35
+ import { Field as Field3 } from "payload";
36
+ type SlugFieldOptions = {
37
+ /** Field name. Default: `'slug'`. */
38
+ name?: string;
39
+ /**
40
+ * Allow the `_` nesting divider in the slug so `about_us` renders at
41
+ * `/about/us`. Relaxes validation and documents the convention in the
42
+ * admin UI. Pair with `createCollectionPageExports({ nested: true })`.
43
+ * Default: `false`.
44
+ */
45
+ nested?: boolean;
46
+ /**
47
+ * Localize the slug — one slug per locale (`/about` in `en`, `/o-nas`
48
+ * in `sk`), stored in the collection's `_locales` table. This is the
49
+ * default: the lib's collections are multilingual, so per-locale slugs
50
+ * power localized URLs and hreflang alternates. Pass `false` for a
51
+ * single shared slug.
52
+ */
53
+ localized?: boolean;
54
+ };
55
+ /**
56
+ * The slug field shared by the lib's Pages / Posts collections: a
57
+ * required, unique, indexed, sidebar text field, localized by default.
58
+ *
59
+ * The empty string is reserved for the home page (rendered at
60
+ * `/${locale}`), so validation only rejects non-empty malformed values.
61
+ */
62
+ declare const slugField: (options?: SlugFieldOptions) => Field3;
35
63
  import { Field as Field_14espm } from "payload";
36
64
  declare const _default: {
37
65
  link: (options?: LinkOptions) => Field_14espm;
@@ -40,5 +68,6 @@ declare const _default: {
40
68
  label: string;
41
69
  value: string;
42
70
  }>;
71
+ slugField: (options?: SlugFieldOptions) => Field_14espm;
43
72
  };
44
- export { linkGroup, link, _default as default, appearanceOptions, LinkOptions, LinkAppearances };
73
+ export { slugField, linkGroup, link, _default as default, appearanceOptions, SlugFieldOptions, LinkOptions, LinkAppearances };
@@ -128,9 +128,38 @@ var linkGroup = (options = {}) => ({
128
128
  admin: { initCollapsed: true }
129
129
  });
130
130
 
131
+ // src/core/fields/slug.ts
132
+ var FLAT_PATTERN = /^[a-z0-9-]+$/;
133
+ var NESTED_PATTERN = /^[a-z0-9_-]+$/;
134
+ var slugField = (options = {}) => {
135
+ const { name = "slug", nested = false, localized = true } = options;
136
+ const pattern = nested ? NESTED_PATTERN : FLAT_PATTERN;
137
+ const invalidMessage = nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
138
+ return {
139
+ name,
140
+ type: "text",
141
+ required: true,
142
+ unique: true,
143
+ index: true,
144
+ localized,
145
+ admin: {
146
+ position: "sidebar",
147
+ ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
148
+ },
149
+ validate: (value) => {
150
+ if (typeof value !== "string")
151
+ return "Slug must be a string";
152
+ if (value !== "" && !pattern.test(value))
153
+ return invalidMessage;
154
+ return true;
155
+ }
156
+ };
157
+ };
158
+
131
159
  // src/exports/core-fields.ts
132
- var core_fields_default = { link, linkGroup, appearanceOptions };
160
+ var core_fields_default = { link, linkGroup, appearanceOptions, slugField };
133
161
  export {
162
+ slugField,
134
163
  linkGroup,
135
164
  link,
136
165
  core_fields_default as default,
@@ -24,6 +24,34 @@ var authenticatedOrPublished = ({ req: { user } }) => {
24
24
  return { _status: { equals: "published" } };
25
25
  };
26
26
 
27
+ // src/core/fields/slug.ts
28
+ var FLAT_PATTERN = /^[a-z0-9-]+$/;
29
+ var NESTED_PATTERN = /^[a-z0-9_-]+$/;
30
+ var slugField = (options = {}) => {
31
+ const { name = "slug", nested = false, localized = true } = options;
32
+ const pattern = nested ? NESTED_PATTERN : FLAT_PATTERN;
33
+ const invalidMessage = nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
34
+ return {
35
+ name,
36
+ type: "text",
37
+ required: true,
38
+ unique: true,
39
+ index: true,
40
+ localized,
41
+ admin: {
42
+ position: "sidebar",
43
+ ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
44
+ },
45
+ validate: (value) => {
46
+ if (typeof value !== "string")
47
+ return "Slug must be a string";
48
+ if (value !== "" && !pattern.test(value))
49
+ return invalidMessage;
50
+ return true;
51
+ }
52
+ };
53
+ };
54
+
27
55
  // src/render/_locale.ts
28
56
  function prefixFor(locale, defaultLocale, mode) {
29
57
  if (mode === "never")
@@ -198,26 +226,6 @@ var createPagesCollection = (blocks, options = {}) => {
198
226
  defaultLocale,
199
227
  nested = false
200
228
  } = options;
201
- const slugPattern = nested ? /^[a-z0-9_-]+$/ : /^[a-z0-9-]+$/;
202
- const slugField = {
203
- name: "slug",
204
- type: "text",
205
- required: true,
206
- unique: true,
207
- index: true,
208
- admin: {
209
- position: "sidebar",
210
- ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
211
- },
212
- validate: (value) => {
213
- if (typeof value !== "string")
214
- return "Slug must be a string";
215
- if (value !== "" && !slugPattern.test(value)) {
216
- return nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
217
- }
218
- return true;
219
- }
220
- };
221
229
  const baseFields = [
222
230
  {
223
231
  name: "title",
@@ -247,7 +255,7 @@ var createPagesCollection = (blocks, options = {}) => {
247
255
  type: "date",
248
256
  admin: { position: "sidebar" }
249
257
  },
250
- slugField
258
+ slugField({ nested })
251
259
  ];
252
260
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
253
261
  collectionSlug,
@@ -282,14 +290,6 @@ var createPostsCollection = (options = {}) => {
282
290
  localePrefix,
283
291
  defaultLocale
284
292
  } = options;
285
- const slugField = {
286
- name: "slug",
287
- type: "text",
288
- required: true,
289
- unique: true,
290
- index: true,
291
- admin: { position: "sidebar" }
292
- };
293
293
  const baseFields = [
294
294
  {
295
295
  name: "title",
@@ -314,7 +314,7 @@ var createPostsCollection = (options = {}) => {
314
314
  type: "date",
315
315
  admin: { position: "sidebar" }
316
316
  },
317
- slugField
317
+ slugField()
318
318
  ];
319
319
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
320
320
  collectionSlug,
package/dist/data-test.js CHANGED
@@ -30,6 +30,34 @@ var authenticatedOrPublished = ({ req: { user } }) => {
30
30
  return { _status: { equals: "published" } };
31
31
  };
32
32
 
33
+ // src/core/fields/slug.ts
34
+ var FLAT_PATTERN = /^[a-z0-9-]+$/;
35
+ var NESTED_PATTERN = /^[a-z0-9_-]+$/;
36
+ var slugField = (options = {}) => {
37
+ const { name = "slug", nested = false, localized = true } = options;
38
+ const pattern = nested ? NESTED_PATTERN : FLAT_PATTERN;
39
+ const invalidMessage = nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
40
+ return {
41
+ name,
42
+ type: "text",
43
+ required: true,
44
+ unique: true,
45
+ index: true,
46
+ localized,
47
+ admin: {
48
+ position: "sidebar",
49
+ ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
50
+ },
51
+ validate: (value) => {
52
+ if (typeof value !== "string")
53
+ return "Slug must be a string";
54
+ if (value !== "" && !pattern.test(value))
55
+ return invalidMessage;
56
+ return true;
57
+ }
58
+ };
59
+ };
60
+
33
61
  // src/render/_locale.ts
34
62
  function prefixFor(locale, defaultLocale, mode) {
35
63
  if (mode === "never")
@@ -204,26 +232,6 @@ var createPagesCollection = (blocks, options = {}) => {
204
232
  defaultLocale,
205
233
  nested = false
206
234
  } = options;
207
- const slugPattern = nested ? /^[a-z0-9_-]+$/ : /^[a-z0-9-]+$/;
208
- const slugField = {
209
- name: "slug",
210
- type: "text",
211
- required: true,
212
- unique: true,
213
- index: true,
214
- admin: {
215
- position: "sidebar",
216
- ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
217
- },
218
- validate: (value) => {
219
- if (typeof value !== "string")
220
- return "Slug must be a string";
221
- if (value !== "" && !slugPattern.test(value)) {
222
- return nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
223
- }
224
- return true;
225
- }
226
- };
227
235
  const baseFields = [
228
236
  {
229
237
  name: "title",
@@ -253,7 +261,7 @@ var createPagesCollection = (blocks, options = {}) => {
253
261
  type: "date",
254
262
  admin: { position: "sidebar" }
255
263
  },
256
- slugField
264
+ slugField({ nested })
257
265
  ];
258
266
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
259
267
  collectionSlug,
@@ -288,14 +296,6 @@ var createPostsCollection = (options = {}) => {
288
296
  localePrefix,
289
297
  defaultLocale
290
298
  } = options;
291
- const slugField = {
292
- name: "slug",
293
- type: "text",
294
- required: true,
295
- unique: true,
296
- index: true,
297
- admin: { position: "sidebar" }
298
- };
299
299
  const baseFields = [
300
300
  {
301
301
  name: "title",
@@ -320,7 +320,7 @@ var createPostsCollection = (options = {}) => {
320
320
  type: "date",
321
321
  admin: { position: "sidebar" }
322
322
  },
323
- slugField
323
+ slugField()
324
324
  ];
325
325
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
326
326
  collectionSlug,
@@ -672,7 +672,7 @@ function getFromImportMap(key, importMap) {
672
672
  var queryDocBySlug = cache(async function queryDocBySlug2({
673
673
  collectionSlug,
674
674
  slug,
675
- slugField = "slug",
675
+ slugField: slugField2 = "slug",
676
676
  locale,
677
677
  draft = false,
678
678
  config
@@ -684,14 +684,14 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
684
684
  limit: 1,
685
685
  pagination: false,
686
686
  overrideAccess: draft,
687
- where: { [slugField]: { equals: slug } },
687
+ where: { [slugField2]: { equals: slug } },
688
688
  locale
689
689
  });
690
690
  return result.docs?.[0] ?? null;
691
691
  });
692
692
  var queryAllDocs = cache(async function queryAllDocs2({
693
693
  collectionSlug,
694
- slugField = "slug",
694
+ slugField: slugField2 = "slug",
695
695
  locale,
696
696
  config
697
697
  }) {
@@ -702,7 +702,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
702
702
  limit: 1000,
703
703
  pagination: false,
704
704
  overrideAccess: false,
705
- select: { [slugField]: true },
705
+ select: { [slugField2]: true },
706
706
  locale
707
707
  });
708
708
  return result.docs ?? [];
@@ -710,7 +710,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
710
710
  var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
711
711
  collectionSlug,
712
712
  slug,
713
- slugField = "slug",
713
+ slugField: slugField2 = "slug",
714
714
  locale,
715
715
  config
716
716
  }) {
@@ -722,13 +722,25 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
722
722
  pagination: false,
723
723
  overrideAccess: false,
724
724
  locale,
725
- where: { [slugField]: { equals: slug } },
726
- select: { [slugField]: true }
725
+ where: { [slugField2]: { equals: slug } },
726
+ select: { [slugField2]: true }
727
727
  });
728
728
  const doc = result.docs?.[0];
729
729
  if (!doc)
730
730
  return;
731
- const fieldValue = doc?.[slugField];
731
+ let fieldValue = doc[slugField2];
732
+ if (doc.id != null) {
733
+ const allLocales2 = await payload.findByID({
734
+ collection: collectionSlug,
735
+ id: doc.id,
736
+ locale: "all",
737
+ draft: false,
738
+ overrideAccess: false,
739
+ select: { [slugField2]: true }
740
+ }).catch(() => null);
741
+ if (allLocales2)
742
+ fieldValue = allLocales2[slugField2];
743
+ }
732
744
  if (fieldValue && typeof fieldValue === "object") {
733
745
  return fieldValue;
734
746
  }
package/dist/fields.d.ts CHANGED
@@ -32,6 +32,34 @@ type LinkOptions = {
32
32
  declare const link: (options?: LinkOptions) => Field;
33
33
  import { Field as Field2 } from "payload";
34
34
  declare const linkGroup: (options?: LinkOptions) => Field2;
35
+ import { Field as Field3 } from "payload";
36
+ type SlugFieldOptions = {
37
+ /** Field name. Default: `'slug'`. */
38
+ name?: string;
39
+ /**
40
+ * Allow the `_` nesting divider in the slug so `about_us` renders at
41
+ * `/about/us`. Relaxes validation and documents the convention in the
42
+ * admin UI. Pair with `createCollectionPageExports({ nested: true })`.
43
+ * Default: `false`.
44
+ */
45
+ nested?: boolean;
46
+ /**
47
+ * Localize the slug — one slug per locale (`/about` in `en`, `/o-nas`
48
+ * in `sk`), stored in the collection's `_locales` table. This is the
49
+ * default: the lib's collections are multilingual, so per-locale slugs
50
+ * power localized URLs and hreflang alternates. Pass `false` for a
51
+ * single shared slug.
52
+ */
53
+ localized?: boolean;
54
+ };
55
+ /**
56
+ * The slug field shared by the lib's Pages / Posts collections: a
57
+ * required, unique, indexed, sidebar text field, localized by default.
58
+ *
59
+ * The empty string is reserved for the home page (rendered at
60
+ * `/${locale}`), so validation only rejects non-empty malformed values.
61
+ */
62
+ declare const slugField: (options?: SlugFieldOptions) => Field3;
35
63
  import { Field as Field_14espm } from "payload";
36
64
  declare const _default: {
37
65
  link: (options?: LinkOptions) => Field_14espm;
@@ -40,5 +68,6 @@ declare const _default: {
40
68
  label: string;
41
69
  value: string;
42
70
  }>;
71
+ slugField: (options?: SlugFieldOptions) => Field_14espm;
43
72
  };
44
- export { linkGroup, link, _default as default, appearanceOptions, LinkOptions, LinkAppearances };
73
+ export { slugField, linkGroup, link, _default as default, appearanceOptions, SlugFieldOptions, LinkOptions, LinkAppearances };
package/dist/fields.js CHANGED
@@ -128,9 +128,38 @@ var linkGroup = (options = {}) => ({
128
128
  admin: { initCollapsed: true }
129
129
  });
130
130
 
131
+ // src/core/fields/slug.ts
132
+ var FLAT_PATTERN = /^[a-z0-9-]+$/;
133
+ var NESTED_PATTERN = /^[a-z0-9_-]+$/;
134
+ var slugField = (options = {}) => {
135
+ const { name = "slug", nested = false, localized = true } = options;
136
+ const pattern = nested ? NESTED_PATTERN : FLAT_PATTERN;
137
+ const invalidMessage = nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
138
+ return {
139
+ name,
140
+ type: "text",
141
+ required: true,
142
+ unique: true,
143
+ index: true,
144
+ localized,
145
+ admin: {
146
+ position: "sidebar",
147
+ ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
148
+ },
149
+ validate: (value) => {
150
+ if (typeof value !== "string")
151
+ return "Slug must be a string";
152
+ if (value !== "" && !pattern.test(value))
153
+ return invalidMessage;
154
+ return true;
155
+ }
156
+ };
157
+ };
158
+
131
159
  // src/exports/fields.ts
132
- var fields_default = { link, linkGroup, appearanceOptions };
160
+ var fields_default = { link, linkGroup, appearanceOptions, slugField };
133
161
  export {
162
+ slugField,
134
163
  linkGroup,
135
164
  link,
136
165
  fields_default as default,
package/dist/metadata.js CHANGED
@@ -262,7 +262,19 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
262
262
  const doc = result.docs?.[0];
263
263
  if (!doc)
264
264
  return;
265
- const fieldValue = doc?.[slugField];
265
+ let fieldValue = doc[slugField];
266
+ if (doc.id != null) {
267
+ const allLocales = await payload.findByID({
268
+ collection: collectionSlug,
269
+ id: doc.id,
270
+ locale: "all",
271
+ draft: false,
272
+ overrideAccess: false,
273
+ select: { [slugField]: true }
274
+ }).catch(() => null);
275
+ if (allLocales)
276
+ fieldValue = allLocales[slugField];
277
+ }
266
278
  if (fieldValue && typeof fieldValue === "object") {
267
279
  return fieldValue;
268
280
  }
package/dist/pages.js CHANGED
@@ -639,7 +639,19 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
639
639
  const doc = result.docs?.[0];
640
640
  if (!doc)
641
641
  return;
642
- const fieldValue = doc?.[slugField];
642
+ let fieldValue = doc[slugField];
643
+ if (doc.id != null) {
644
+ const allLocales = await payload.findByID({
645
+ collection: collectionSlug,
646
+ id: doc.id,
647
+ locale: "all",
648
+ draft: false,
649
+ overrideAccess: false,
650
+ select: { [slugField]: true }
651
+ }).catch(() => null);
652
+ if (allLocales)
653
+ fieldValue = allLocales[slugField];
654
+ }
643
655
  if (fieldValue && typeof fieldValue === "object") {
644
656
  return fieldValue;
645
657
  }
@@ -262,7 +262,19 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
262
262
  const doc = result.docs?.[0];
263
263
  if (!doc)
264
264
  return;
265
- const fieldValue = doc?.[slugField];
265
+ let fieldValue = doc[slugField];
266
+ if (doc.id != null) {
267
+ const allLocales = await payload.findByID({
268
+ collection: collectionSlug,
269
+ id: doc.id,
270
+ locale: "all",
271
+ draft: false,
272
+ overrideAccess: false,
273
+ select: { [slugField]: true }
274
+ }).catch(() => null);
275
+ if (allLocales)
276
+ fieldValue = allLocales[slugField];
277
+ }
266
278
  if (fieldValue && typeof fieldValue === "object") {
267
279
  return fieldValue;
268
280
  }
@@ -460,7 +460,19 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
460
460
  const doc = result.docs?.[0];
461
461
  if (!doc)
462
462
  return;
463
- const fieldValue = doc?.[slugField];
463
+ let fieldValue = doc[slugField];
464
+ if (doc.id != null) {
465
+ const allLocales = await payload.findByID({
466
+ collection: collectionSlug,
467
+ id: doc.id,
468
+ locale: "all",
469
+ draft: false,
470
+ overrideAccess: false,
471
+ select: { [slugField]: true }
472
+ }).catch(() => null);
473
+ if (allLocales)
474
+ fieldValue = allLocales[slugField];
475
+ }
464
476
  if (fieldValue && typeof fieldValue === "object") {
465
477
  return fieldValue;
466
478
  }
@@ -226,7 +226,19 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
226
226
  const doc = result.docs?.[0];
227
227
  if (!doc)
228
228
  return;
229
- const fieldValue = doc?.[slugField];
229
+ let fieldValue = doc[slugField];
230
+ if (doc.id != null) {
231
+ const allLocales2 = await payload.findByID({
232
+ collection: collectionSlug,
233
+ id: doc.id,
234
+ locale: "all",
235
+ draft: false,
236
+ overrideAccess: false,
237
+ select: { [slugField]: true }
238
+ }).catch(() => null);
239
+ if (allLocales2)
240
+ fieldValue = allLocales2[slugField];
241
+ }
230
242
  if (fieldValue && typeof fieldValue === "object") {
231
243
  return fieldValue;
232
244
  }
package/dist/server.js CHANGED
@@ -193,6 +193,34 @@ var authenticatedOrPublished = ({ req: { user } }) => {
193
193
  return { _status: { equals: "published" } };
194
194
  };
195
195
 
196
+ // src/core/fields/slug.ts
197
+ var FLAT_PATTERN = /^[a-z0-9-]+$/;
198
+ var NESTED_PATTERN = /^[a-z0-9_-]+$/;
199
+ var slugField = (options = {}) => {
200
+ const { name = "slug", nested = false, localized = true } = options;
201
+ const pattern = nested ? NESTED_PATTERN : FLAT_PATTERN;
202
+ const invalidMessage = nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
203
+ return {
204
+ name,
205
+ type: "text",
206
+ required: true,
207
+ unique: true,
208
+ index: true,
209
+ localized,
210
+ admin: {
211
+ position: "sidebar",
212
+ ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
213
+ },
214
+ validate: (value) => {
215
+ if (typeof value !== "string")
216
+ return "Slug must be a string";
217
+ if (value !== "" && !pattern.test(value))
218
+ return invalidMessage;
219
+ return true;
220
+ }
221
+ };
222
+ };
223
+
196
224
  // src/render/_locale.ts
197
225
  function prefixFor(locale, defaultLocale, mode) {
198
226
  if (mode === "never")
@@ -367,26 +395,6 @@ var createPagesCollection = (blocks, options = {}) => {
367
395
  defaultLocale,
368
396
  nested = false
369
397
  } = options;
370
- const slugPattern = nested ? /^[a-z0-9_-]+$/ : /^[a-z0-9-]+$/;
371
- const slugField = {
372
- name: "slug",
373
- type: "text",
374
- required: true,
375
- unique: true,
376
- index: true,
377
- admin: {
378
- position: "sidebar",
379
- ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
380
- },
381
- validate: (value) => {
382
- if (typeof value !== "string")
383
- return "Slug must be a string";
384
- if (value !== "" && !slugPattern.test(value)) {
385
- return nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
386
- }
387
- return true;
388
- }
389
- };
390
398
  const baseFields = [
391
399
  {
392
400
  name: "title",
@@ -416,7 +424,7 @@ var createPagesCollection = (blocks, options = {}) => {
416
424
  type: "date",
417
425
  admin: { position: "sidebar" }
418
426
  },
419
- slugField
427
+ slugField({ nested })
420
428
  ];
421
429
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
422
430
  collectionSlug,
@@ -451,14 +459,6 @@ var createPostsCollection = (options = {}) => {
451
459
  localePrefix,
452
460
  defaultLocale
453
461
  } = options;
454
- const slugField = {
455
- name: "slug",
456
- type: "text",
457
- required: true,
458
- unique: true,
459
- index: true,
460
- admin: { position: "sidebar" }
461
- };
462
462
  const baseFields = [
463
463
  {
464
464
  name: "title",
@@ -483,7 +483,7 @@ var createPostsCollection = (options = {}) => {
483
483
  type: "date",
484
484
  admin: { position: "sidebar" }
485
485
  },
486
- slugField
486
+ slugField()
487
487
  ];
488
488
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
489
489
  collectionSlug,
@@ -835,7 +835,7 @@ function getFromImportMap(key, importMap) {
835
835
  var queryDocBySlug = cache(async function queryDocBySlug2({
836
836
  collectionSlug,
837
837
  slug,
838
- slugField = "slug",
838
+ slugField: slugField2 = "slug",
839
839
  locale,
840
840
  draft = false,
841
841
  config
@@ -847,14 +847,14 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
847
847
  limit: 1,
848
848
  pagination: false,
849
849
  overrideAccess: draft,
850
- where: { [slugField]: { equals: slug } },
850
+ where: { [slugField2]: { equals: slug } },
851
851
  locale
852
852
  });
853
853
  return result.docs?.[0] ?? null;
854
854
  });
855
855
  var queryAllDocs = cache(async function queryAllDocs2({
856
856
  collectionSlug,
857
- slugField = "slug",
857
+ slugField: slugField2 = "slug",
858
858
  locale,
859
859
  config
860
860
  }) {
@@ -865,7 +865,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
865
865
  limit: 1000,
866
866
  pagination: false,
867
867
  overrideAccess: false,
868
- select: { [slugField]: true },
868
+ select: { [slugField2]: true },
869
869
  locale
870
870
  });
871
871
  return result.docs ?? [];
@@ -873,7 +873,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
873
873
  var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
874
874
  collectionSlug,
875
875
  slug,
876
- slugField = "slug",
876
+ slugField: slugField2 = "slug",
877
877
  locale,
878
878
  config
879
879
  }) {
@@ -885,13 +885,25 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
885
885
  pagination: false,
886
886
  overrideAccess: false,
887
887
  locale,
888
- where: { [slugField]: { equals: slug } },
889
- select: { [slugField]: true }
888
+ where: { [slugField2]: { equals: slug } },
889
+ select: { [slugField2]: true }
890
890
  });
891
891
  const doc = result.docs?.[0];
892
892
  if (!doc)
893
893
  return;
894
- const fieldValue = doc?.[slugField];
894
+ let fieldValue = doc[slugField2];
895
+ if (doc.id != null) {
896
+ const allLocales2 = await payload.findByID({
897
+ collection: collectionSlug,
898
+ id: doc.id,
899
+ locale: "all",
900
+ draft: false,
901
+ overrideAccess: false,
902
+ select: { [slugField2]: true }
903
+ }).catch(() => null);
904
+ if (allLocales2)
905
+ fieldValue = allLocales2[slugField2];
906
+ }
895
907
  if (fieldValue && typeof fieldValue === "object") {
896
908
  return fieldValue;
897
909
  }
package/dist/test.js CHANGED
@@ -30,6 +30,34 @@ var authenticatedOrPublished = ({ req: { user } }) => {
30
30
  return { _status: { equals: "published" } };
31
31
  };
32
32
 
33
+ // src/core/fields/slug.ts
34
+ var FLAT_PATTERN = /^[a-z0-9-]+$/;
35
+ var NESTED_PATTERN = /^[a-z0-9_-]+$/;
36
+ var slugField = (options = {}) => {
37
+ const { name = "slug", nested = false, localized = true } = options;
38
+ const pattern = nested ? NESTED_PATTERN : FLAT_PATTERN;
39
+ const invalidMessage = nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
40
+ return {
41
+ name,
42
+ type: "text",
43
+ required: true,
44
+ unique: true,
45
+ index: true,
46
+ localized,
47
+ admin: {
48
+ position: "sidebar",
49
+ ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
50
+ },
51
+ validate: (value) => {
52
+ if (typeof value !== "string")
53
+ return "Slug must be a string";
54
+ if (value !== "" && !pattern.test(value))
55
+ return invalidMessage;
56
+ return true;
57
+ }
58
+ };
59
+ };
60
+
33
61
  // src/render/_locale.ts
34
62
  function prefixFor(locale, defaultLocale, mode) {
35
63
  if (mode === "never")
@@ -204,26 +232,6 @@ var createPagesCollection = (blocks, options = {}) => {
204
232
  defaultLocale,
205
233
  nested = false
206
234
  } = options;
207
- const slugPattern = nested ? /^[a-z0-9_-]+$/ : /^[a-z0-9-]+$/;
208
- const slugField = {
209
- name: "slug",
210
- type: "text",
211
- required: true,
212
- unique: true,
213
- index: true,
214
- admin: {
215
- position: "sidebar",
216
- ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
217
- },
218
- validate: (value) => {
219
- if (typeof value !== "string")
220
- return "Slug must be a string";
221
- if (value !== "" && !slugPattern.test(value)) {
222
- return nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
223
- }
224
- return true;
225
- }
226
- };
227
235
  const baseFields = [
228
236
  {
229
237
  name: "title",
@@ -253,7 +261,7 @@ var createPagesCollection = (blocks, options = {}) => {
253
261
  type: "date",
254
262
  admin: { position: "sidebar" }
255
263
  },
256
- slugField
264
+ slugField({ nested })
257
265
  ];
258
266
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
259
267
  collectionSlug,
@@ -288,14 +296,6 @@ var createPostsCollection = (options = {}) => {
288
296
  localePrefix,
289
297
  defaultLocale
290
298
  } = options;
291
- const slugField = {
292
- name: "slug",
293
- type: "text",
294
- required: true,
295
- unique: true,
296
- index: true,
297
- admin: { position: "sidebar" }
298
- };
299
299
  const baseFields = [
300
300
  {
301
301
  name: "title",
@@ -320,7 +320,7 @@ var createPostsCollection = (options = {}) => {
320
320
  type: "date",
321
321
  admin: { position: "sidebar" }
322
322
  },
323
- slugField
323
+ slugField()
324
324
  ];
325
325
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
326
326
  collectionSlug,
@@ -672,7 +672,7 @@ function getFromImportMap(key, importMap) {
672
672
  var queryDocBySlug = cache(async function queryDocBySlug2({
673
673
  collectionSlug,
674
674
  slug,
675
- slugField = "slug",
675
+ slugField: slugField2 = "slug",
676
676
  locale,
677
677
  draft = false,
678
678
  config
@@ -684,14 +684,14 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
684
684
  limit: 1,
685
685
  pagination: false,
686
686
  overrideAccess: draft,
687
- where: { [slugField]: { equals: slug } },
687
+ where: { [slugField2]: { equals: slug } },
688
688
  locale
689
689
  });
690
690
  return result.docs?.[0] ?? null;
691
691
  });
692
692
  var queryAllDocs = cache(async function queryAllDocs2({
693
693
  collectionSlug,
694
- slugField = "slug",
694
+ slugField: slugField2 = "slug",
695
695
  locale,
696
696
  config
697
697
  }) {
@@ -702,7 +702,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
702
702
  limit: 1000,
703
703
  pagination: false,
704
704
  overrideAccess: false,
705
- select: { [slugField]: true },
705
+ select: { [slugField2]: true },
706
706
  locale
707
707
  });
708
708
  return result.docs ?? [];
@@ -710,7 +710,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
710
710
  var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
711
711
  collectionSlug,
712
712
  slug,
713
- slugField = "slug",
713
+ slugField: slugField2 = "slug",
714
714
  locale,
715
715
  config
716
716
  }) {
@@ -722,13 +722,25 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
722
722
  pagination: false,
723
723
  overrideAccess: false,
724
724
  locale,
725
- where: { [slugField]: { equals: slug } },
726
- select: { [slugField]: true }
725
+ where: { [slugField2]: { equals: slug } },
726
+ select: { [slugField2]: true }
727
727
  });
728
728
  const doc = result.docs?.[0];
729
729
  if (!doc)
730
730
  return;
731
- const fieldValue = doc?.[slugField];
731
+ let fieldValue = doc[slugField2];
732
+ if (doc.id != null) {
733
+ const allLocales2 = await payload.findByID({
734
+ collection: collectionSlug,
735
+ id: doc.id,
736
+ locale: "all",
737
+ draft: false,
738
+ overrideAccess: false,
739
+ select: { [slugField2]: true }
740
+ }).catch(() => null);
741
+ if (allLocales2)
742
+ fieldValue = allLocales2[slugField2];
743
+ }
732
744
  if (fieldValue && typeof fieldValue === "object") {
733
745
  return fieldValue;
734
746
  }
@@ -24,6 +24,34 @@ var authenticatedOrPublished = ({ req: { user } }) => {
24
24
  return { _status: { equals: "published" } };
25
25
  };
26
26
 
27
+ // src/core/fields/slug.ts
28
+ var FLAT_PATTERN = /^[a-z0-9-]+$/;
29
+ var NESTED_PATTERN = /^[a-z0-9_-]+$/;
30
+ var slugField = (options = {}) => {
31
+ const { name = "slug", nested = false, localized = true } = options;
32
+ const pattern = nested ? NESTED_PATTERN : FLAT_PATTERN;
33
+ const invalidMessage = nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
34
+ return {
35
+ name,
36
+ type: "text",
37
+ required: true,
38
+ unique: true,
39
+ index: true,
40
+ localized,
41
+ admin: {
42
+ position: "sidebar",
43
+ ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
44
+ },
45
+ validate: (value) => {
46
+ if (typeof value !== "string")
47
+ return "Slug must be a string";
48
+ if (value !== "" && !pattern.test(value))
49
+ return invalidMessage;
50
+ return true;
51
+ }
52
+ };
53
+ };
54
+
27
55
  // src/render/_locale.ts
28
56
  function prefixFor(locale, defaultLocale, mode) {
29
57
  if (mode === "never")
@@ -198,26 +226,6 @@ var createPagesCollection = (blocks, options = {}) => {
198
226
  defaultLocale,
199
227
  nested = false
200
228
  } = options;
201
- const slugPattern = nested ? /^[a-z0-9_-]+$/ : /^[a-z0-9-]+$/;
202
- const slugField = {
203
- name: "slug",
204
- type: "text",
205
- required: true,
206
- unique: true,
207
- index: true,
208
- admin: {
209
- position: "sidebar",
210
- ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
211
- },
212
- validate: (value) => {
213
- if (typeof value !== "string")
214
- return "Slug must be a string";
215
- if (value !== "" && !slugPattern.test(value)) {
216
- return nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
217
- }
218
- return true;
219
- }
220
- };
221
229
  const baseFields = [
222
230
  {
223
231
  name: "title",
@@ -247,7 +255,7 @@ var createPagesCollection = (blocks, options = {}) => {
247
255
  type: "date",
248
256
  admin: { position: "sidebar" }
249
257
  },
250
- slugField
258
+ slugField({ nested })
251
259
  ];
252
260
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
253
261
  collectionSlug,
@@ -282,14 +290,6 @@ var createPostsCollection = (options = {}) => {
282
290
  localePrefix,
283
291
  defaultLocale
284
292
  } = options;
285
- const slugField = {
286
- name: "slug",
287
- type: "text",
288
- required: true,
289
- unique: true,
290
- index: true,
291
- admin: { position: "sidebar" }
292
- };
293
293
  const baseFields = [
294
294
  {
295
295
  name: "title",
@@ -314,7 +314,7 @@ var createPostsCollection = (options = {}) => {
314
314
  type: "date",
315
315
  admin: { position: "sidebar" }
316
316
  },
317
- slugField
317
+ slugField()
318
318
  ];
319
319
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
320
320
  collectionSlug,
@@ -666,7 +666,7 @@ function getFromImportMap(key, importMap) {
666
666
  var queryDocBySlug = cache(async function queryDocBySlug2({
667
667
  collectionSlug,
668
668
  slug,
669
- slugField = "slug",
669
+ slugField: slugField2 = "slug",
670
670
  locale,
671
671
  draft = false,
672
672
  config
@@ -678,14 +678,14 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
678
678
  limit: 1,
679
679
  pagination: false,
680
680
  overrideAccess: draft,
681
- where: { [slugField]: { equals: slug } },
681
+ where: { [slugField2]: { equals: slug } },
682
682
  locale
683
683
  });
684
684
  return result.docs?.[0] ?? null;
685
685
  });
686
686
  var queryAllDocs = cache(async function queryAllDocs2({
687
687
  collectionSlug,
688
- slugField = "slug",
688
+ slugField: slugField2 = "slug",
689
689
  locale,
690
690
  config
691
691
  }) {
@@ -696,7 +696,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
696
696
  limit: 1000,
697
697
  pagination: false,
698
698
  overrideAccess: false,
699
- select: { [slugField]: true },
699
+ select: { [slugField2]: true },
700
700
  locale
701
701
  });
702
702
  return result.docs ?? [];
@@ -704,7 +704,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
704
704
  var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
705
705
  collectionSlug,
706
706
  slug,
707
- slugField = "slug",
707
+ slugField: slugField2 = "slug",
708
708
  locale,
709
709
  config
710
710
  }) {
@@ -716,13 +716,25 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
716
716
  pagination: false,
717
717
  overrideAccess: false,
718
718
  locale,
719
- where: { [slugField]: { equals: slug } },
720
- select: { [slugField]: true }
719
+ where: { [slugField2]: { equals: slug } },
720
+ select: { [slugField2]: true }
721
721
  });
722
722
  const doc = result.docs?.[0];
723
723
  if (!doc)
724
724
  return;
725
- const fieldValue = doc?.[slugField];
725
+ let fieldValue = doc[slugField2];
726
+ if (doc.id != null) {
727
+ const allLocales2 = await payload.findByID({
728
+ collection: collectionSlug,
729
+ id: doc.id,
730
+ locale: "all",
731
+ draft: false,
732
+ overrideAccess: false,
733
+ select: { [slugField2]: true }
734
+ }).catch(() => null);
735
+ if (allLocales2)
736
+ fieldValue = allLocales2[slugField2];
737
+ }
726
738
  if (fieldValue && typeof fieldValue === "object") {
727
739
  return fieldValue;
728
740
  }
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.2.0",
4
+ "version": "0.3.1",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "module": "./dist/index.js",