@ainsleydev/payload-helper 0.0.3 → 0.0.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.
Files changed (55) hide show
  1. package/bin.js +7 -0
  2. package/dist/cli/bin.d.ts +2 -0
  3. package/dist/cli/bin.js +17 -0
  4. package/dist/cli/bin.js.map +1 -0
  5. package/dist/cli/types.d.ts +4 -0
  6. package/dist/cli/types.js +34 -0
  7. package/dist/cli/types.js.map +1 -0
  8. package/dist/collections/Media.js +150 -0
  9. package/dist/collections/Media.js.map +1 -0
  10. package/dist/collections/Redirects.js +72 -0
  11. package/dist/collections/Redirects.js.map +1 -0
  12. package/dist/common/SEO.js +45 -0
  13. package/dist/common/SEO.js.map +1 -0
  14. package/dist/endpoints/slug.js +39 -0
  15. package/dist/endpoints/slug.js.map +1 -0
  16. package/dist/globals/Navigation.js +138 -0
  17. package/dist/globals/Navigation.js.map +1 -0
  18. package/dist/globals/Settings.js +346 -0
  19. package/dist/globals/Settings.js.map +1 -0
  20. package/dist/globals/countries.js +198 -0
  21. package/dist/globals/countries.js.map +1 -0
  22. package/dist/globals/locales.js +2664 -0
  23. package/dist/globals/locales.js.map +1 -0
  24. package/dist/index.js +22 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/jest.config.js +27 -0
  27. package/dist/jest.config.js.map +1 -0
  28. package/dist/plugin/schema.js +239 -0
  29. package/dist/plugin/schema.js.map +1 -0
  30. package/dist/util/env.js +75 -0
  31. package/dist/util/env.js.map +1 -0
  32. package/dist/util/fields.js +12 -0
  33. package/dist/util/fields.js.map +1 -0
  34. package/dist/util/lexical.js +53 -0
  35. package/dist/util/lexical.js.map +1 -0
  36. package/dist/util/lexical.test.js +21 -0
  37. package/dist/util/lexical.test.js.map +1 -0
  38. package/dist/util/validation.js +23 -0
  39. package/dist/util/validation.js.map +1 -0
  40. package/package.json +42 -10
  41. package/eslint.config.mjs +0 -4
  42. package/src/collections/Media.ts +0 -154
  43. package/src/collections/Redirects.ts +0 -56
  44. package/src/common/SEO.ts +0 -45
  45. package/src/endpoints/slug.ts +0 -32
  46. package/src/gen/schema.ts +0 -584
  47. package/src/globals/Navigation.ts +0 -165
  48. package/src/globals/Settings.ts +0 -356
  49. package/src/globals/countries.ts +0 -196
  50. package/src/globals/locales.ts +0 -2668
  51. package/src/scripts/.gitkeep +0 -0
  52. package/src/seed/.gitkeep +0 -0
  53. package/src/util/env.ts +0 -96
  54. package/src/util/validation.ts +0 -22
  55. package/tsconfig.json +0 -19
@@ -0,0 +1,53 @@
1
+ import { createHeadlessEditor } from '@lexical/headless';
2
+ import { $generateNodesFromDOM, $generateHtmlFromNodes } from '@lexical/html';
3
+ import { $getRoot, $getSelection } from 'lexical';
4
+ import { JSDOM } from 'jsdom';
5
+ const editor = createHeadlessEditor({
6
+ nodes: [],
7
+ onError: ()=>{}
8
+ });
9
+ /**
10
+ * Converts an HTML string to a Lexical editor state.
11
+ *
12
+ * @param {string} html - The HTML string to convert.
13
+ * @returns {SerializedEditorState} The serialized editor state.
14
+ */ export const htmlToLexical = (html)=>{
15
+ editor.update(()=>{
16
+ // In a headless environment you can use a package such as JSDom to parse the HTML string.
17
+ const dom = new JSDOM(html);
18
+ // Once you have the DOM instance it's easy to generate LexicalNodes.
19
+ const nodes = $generateNodesFromDOM(editor, dom.window.document);
20
+ // Select the root
21
+ $getRoot().select();
22
+ // Insert them at a selection.
23
+ const selection = $getSelection();
24
+ if (selection) selection.insertNodes(nodes);
25
+ }, {
26
+ discrete: true
27
+ });
28
+ return editor.getEditorState().toJSON();
29
+ };
30
+ /**
31
+ * Converts a Lexical editor state to an HTML string.
32
+ *
33
+ * @param {SerializedEditorState} json - The serialized editor state to convert.
34
+ * @returns {string} The HTML string.
35
+ */ export const lexicalToHtml = (json)=>{
36
+ // Initialize a JSDOM instance
37
+ const dom = new JSDOM('');
38
+ // @ts-ignore
39
+ globalThis.window = dom.window;
40
+ globalThis.document = dom.window.document;
41
+ editor.update(()=>{
42
+ const editorState = editor.parseEditorState(json);
43
+ editor.setEditorState(editorState);
44
+ });
45
+ // Convert the editor state to HTML
46
+ let html = '';
47
+ editor.getEditorState().read(()=>{
48
+ html = $generateHtmlFromNodes(editor);
49
+ });
50
+ return html;
51
+ };
52
+
53
+ //# sourceMappingURL=lexical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/lexical.ts"],"sourcesContent":["import { createHeadlessEditor } from '@lexical/headless';\nimport { $generateNodesFromDOM, $generateHtmlFromNodes } from '@lexical/html';\nimport { $getRoot, $getSelection } from 'lexical';\nimport { JSDOM } from 'jsdom';\nimport type { SerializedEditorState } from 'lexical';\n\nconst editor = createHeadlessEditor({\n\tnodes: [],\n\tonError: () => {},\n});\n\n/**\n * Converts an HTML string to a Lexical editor state.\n *\n * @param {string} html - The HTML string to convert.\n * @returns {SerializedEditorState} The serialized editor state.\n */\nexport const htmlToLexical = (html: string): SerializedEditorState => {\n\teditor.update(\n\t\t() => {\n\t\t\t// In a headless environment you can use a package such as JSDom to parse the HTML string.\n\t\t\tconst dom = new JSDOM(html);\n\n\t\t\t// Once you have the DOM instance it's easy to generate LexicalNodes.\n\t\t\tconst nodes = $generateNodesFromDOM(editor, dom.window.document);\n\n\t\t\t// Select the root\n\t\t\t$getRoot().select();\n\n\t\t\t// Insert them at a selection.\n\t\t\tconst selection = $getSelection();\n\n\t\t\tif (selection) selection.insertNodes(nodes);\n\t\t},\n\t\t{ discrete: true },\n\t);\n\n\treturn editor.getEditorState().toJSON();\n};\n\n/**\n * Converts a Lexical editor state to an HTML string.\n *\n * @param {SerializedEditorState} json - The serialized editor state to convert.\n * @returns {string} The HTML string.\n */\nexport const lexicalToHtml = (json: SerializedEditorState): string => {\n\t// Initialize a JSDOM instance\n\tconst dom = new JSDOM('');\n\n\t// @ts-ignore\n\tglobalThis.window = dom.window;\n\tglobalThis.document = dom.window.document;\n\n\teditor.update(() => {\n\t\tconst editorState = editor.parseEditorState(json);\n\t\teditor.setEditorState(editorState);\n\t});\n\n\t// Convert the editor state to HTML\n\tlet html = '';\n\teditor.getEditorState().read(() => {\n\t\thtml = $generateHtmlFromNodes(editor);\n\t});\n\n\treturn html;\n};\n"],"names":["createHeadlessEditor","$generateNodesFromDOM","$generateHtmlFromNodes","$getRoot","$getSelection","JSDOM","editor","nodes","onError","htmlToLexical","html","update","dom","window","document","select","selection","insertNodes","discrete","getEditorState","toJSON","lexicalToHtml","json","globalThis","editorState","parseEditorState","setEditorState","read"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,oBAAoB;AACzD,SAASC,qBAAqB,EAAEC,sBAAsB,QAAQ,gBAAgB;AAC9E,SAASC,QAAQ,EAAEC,aAAa,QAAQ,UAAU;AAClD,SAASC,KAAK,QAAQ,QAAQ;AAG9B,MAAMC,SAASN,qBAAqB;IACnCO,OAAO,EAAE;IACTC,SAAS,KAAO;AACjB;AAEA;;;;;CAKC,GACD,OAAO,MAAMC,gBAAgB,CAACC;IAC7BJ,OAAOK,MAAM,CACZ;QACC,0FAA0F;QAC1F,MAAMC,MAAM,IAAIP,MAAMK;QAEtB,qEAAqE;QACrE,MAAMH,QAAQN,sBAAsBK,QAAQM,IAAIC,MAAM,CAACC,QAAQ;QAE/D,kBAAkB;QAClBX,WAAWY,MAAM;QAEjB,8BAA8B;QAC9B,MAAMC,YAAYZ;QAElB,IAAIY,WAAWA,UAAUC,WAAW,CAACV;IACtC,GACA;QAAEW,UAAU;IAAK;IAGlB,OAAOZ,OAAOa,cAAc,GAAGC,MAAM;AACtC,EAAE;AAEF;;;;;CAKC,GACD,OAAO,MAAMC,gBAAgB,CAACC;IAC7B,8BAA8B;IAC9B,MAAMV,MAAM,IAAIP,MAAM;IAEtB,aAAa;IACbkB,WAAWV,MAAM,GAAGD,IAAIC,MAAM;IAC9BU,WAAWT,QAAQ,GAAGF,IAAIC,MAAM,CAACC,QAAQ;IAEzCR,OAAOK,MAAM,CAAC;QACb,MAAMa,cAAclB,OAAOmB,gBAAgB,CAACH;QAC5ChB,OAAOoB,cAAc,CAACF;IACvB;IAEA,mCAAmC;IACnC,IAAId,OAAO;IACXJ,OAAOa,cAAc,GAAGQ,IAAI,CAAC;QAC5BjB,OAAOR,uBAAuBI;IAC/B;IAEA,OAAOI;AACR,EAAE"}
@@ -0,0 +1,21 @@
1
+ import { htmlToLexical } from './lexical';
2
+ describe('htmlToLexical', ()=>{
3
+ it('should convert an HTML string to a Lexical editor state', ()=>{
4
+ const html = '<p>Hello, world!</p>';
5
+ const editorState = htmlToLexical(html);
6
+ expect(editorState).toEqual({
7
+ nodes: [
8
+ {
9
+ type: 'paragraph',
10
+ children: [
11
+ {
12
+ text: 'Hello, world!'
13
+ }
14
+ ]
15
+ }
16
+ ]
17
+ });
18
+ });
19
+ });
20
+
21
+ //# sourceMappingURL=lexical.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/lexical.test.ts"],"sourcesContent":["import { htmlToLexical } from './lexical';\n\ndescribe('htmlToLexical', () => {\n\tit('should convert an HTML string to a Lexical editor state', () => {\n\t\tconst html = '<p>Hello, world!</p>';\n\t\tconst editorState = htmlToLexical(html);\n\n\t\texpect(editorState).toEqual({\n\t\t\tnodes: [\n\t\t\t\t{\n\t\t\t\t\ttype: 'paragraph',\n\t\t\t\t\tchildren: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttext: 'Hello, world!',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\t});\n});\n"],"names":["htmlToLexical","describe","it","html","editorState","expect","toEqual","nodes","type","children","text"],"mappings":"AAAA,SAASA,aAAa,QAAQ,YAAY;AAE1CC,SAAS,iBAAiB;IACzBC,GAAG,2DAA2D;QAC7D,MAAMC,OAAO;QACb,MAAMC,cAAcJ,cAAcG;QAElCE,OAAOD,aAAaE,OAAO,CAAC;YAC3BC,OAAO;gBACN;oBACCC,MAAM;oBACNC,UAAU;wBACT;4BACCC,MAAM;wBACP;qBACA;gBACF;aACA;QACF;IACD;AACD"}
@@ -0,0 +1,23 @@
1
+ export const validateURL = async (value)=>{
2
+ if (!value) {
3
+ return true;
4
+ }
5
+ try {
6
+ new URL(value);
7
+ return true;
8
+ } catch (error) {
9
+ return 'Please enter a valid URL';
10
+ }
11
+ };
12
+ export const validatePostcode = async (value)=>{
13
+ if (!value) {
14
+ return true;
15
+ }
16
+ const postcodeRegex = /^[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}$/i;
17
+ if (!postcodeRegex.test(value)) {
18
+ return 'Invalid postcode format';
19
+ }
20
+ return true;
21
+ };
22
+
23
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/validation.ts"],"sourcesContent":["export const validateURL = async (value: string) => {\n\tif (!value) {\n\t\treturn true;\n\t}\n\ttry {\n\t\tnew URL(value);\n\t\treturn true;\n\t} catch (error) {\n\t\treturn 'Please enter a valid URL';\n\t}\n};\n\nexport const validatePostcode = async (value: string) => {\n\tif (!value) {\n\t\treturn true;\n\t}\n\tconst postcodeRegex = /^[A-Z]{1,2}\\d[A-Z\\d]? ?\\d[A-Z]{2}$/i;\n\tif (!postcodeRegex.test(value)) {\n\t\treturn 'Invalid postcode format';\n\t}\n\treturn true;\n};\n"],"names":["validateURL","value","URL","error","validatePostcode","postcodeRegex","test"],"mappings":"AAAA,OAAO,MAAMA,cAAc,OAAOC;IACjC,IAAI,CAACA,OAAO;QACX,OAAO;IACR;IACA,IAAI;QACH,IAAIC,IAAID;QACR,OAAO;IACR,EAAE,OAAOE,OAAO;QACf,OAAO;IACR;AACD,EAAE;AAEF,OAAO,MAAMC,mBAAmB,OAAOH;IACtC,IAAI,CAACA,OAAO;QACX,OAAO;IACR;IACA,MAAMI,gBAAgB;IACtB,IAAI,CAACA,cAAcC,IAAI,CAACL,QAAQ;QAC/B,OAAO;IACR;IACA,OAAO;AACR,EAAE"}
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@ainsleydev/payload-helper",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Payload CMS utilities, collections and global types for ainsley.dev builds",
5
5
  "license": "MIT",
6
+ "type": "module",
6
7
  "keywords": [
7
8
  "payload",
8
- "payloadcms",
9
9
  "cms",
10
- "utilities"
10
+ "plugin",
11
+ "typescript",
12
+ "react"
11
13
  ],
12
14
  "repository": {
13
15
  "type": "git",
@@ -19,20 +21,50 @@
19
21
  "email": "hello@ainsley.dev",
20
22
  "url": "https://ainsley.dev"
21
23
  },
24
+ "main": "./src/index.ts",
25
+ "types": "./src/index.ts",
22
26
  "scripts": {
27
+ "build": "pnpm run clean && pnpm build:types && pnpm build:swc",
28
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
29
+ "build:types": "tsc --emitDeclarationOnly --outDir dist",
30
+ "format": "biome format --write .",
31
+ "lint": "biome lint --write .",
23
32
  "release": "npm publish --access public",
24
- "test": "echo \"Error: no test specified\" && exit 1"
33
+ "clean": "rimraf {dist,*.tsbuildinfo}",
34
+ "test": "jest"
25
35
  },
36
+ "bin": {
37
+ "payload-helper": "bin.js"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "bin.js"
42
+ ],
26
43
  "dependencies": {
44
+ "@lexical/headless": "^0.16.1",
45
+ "@lexical/html": "^0.16.1",
27
46
  "@nouance/payload-better-fields-plugin": "^1.4.1",
28
- "@payloadcms/richtext-slate": "beta",
29
- "@payloadcms/richtext-lexical": "beta",
30
- "json-schema": "^0.4.0",
31
- "payload": "beta",
32
- "pluralize": "^8.0.0"
47
+ "@payloadcms/richtext-lexical": "3.0.0-beta.67",
48
+ "@types/json-schema": "^7.0.15",
49
+ "chalk": "^5.3.0",
50
+ "commander": "^12.1.0",
51
+ "jsdom": "^24.1.1",
52
+ "lexical": "^0.16.1",
53
+ "payload": "3.0.0-beta.67"
33
54
  },
34
55
  "devDependencies": {
35
- "@ainsleydev/eslint-config": "workspace:*"
56
+ "@ainsleydev/eslint-config": "workspace:*",
57
+ "@jest/globals": "^29.7.0",
58
+ "@swc/cli": "^0.4.0",
59
+ "@swc/core": "^1.7.2",
60
+ "@types/jest": "^29.5.12",
61
+ "@types/jsdom": "^21.1.7",
62
+ "jest": "^29.7.0",
63
+ "json-schema": "^0.4.0",
64
+ "rimraf": "3.0.2",
65
+ "ts-jest": "^29.2.3",
66
+ "ts-node": "^10.9.2",
67
+ "typescript": "^5.5.4"
36
68
  },
37
69
  "engines": {
38
70
  "node": ">=18",
package/eslint.config.mjs DELETED
@@ -1,4 +0,0 @@
1
- import config from '@ainsleydev/eslint-config/eslint.config.mjs';
2
-
3
- /** @type { import("eslint").Linter.FlatConfig[] } */
4
- export default [...config];
@@ -1,154 +0,0 @@
1
- import type { CollectionConfig, Field } from 'payload';
2
- import { lexicalEditor } from '@payloadcms/richtext-lexical';
3
-
4
- /**
5
- * Media Collection Configuration
6
- * Additional fields will be appended to the media collection.
7
- *
8
- * @param filePath
9
- * @param additionalFields
10
- * @constructor
11
- */
12
- export const Media = (additionalFields?: Field[]): CollectionConfig => {
13
- return {
14
- slug: 'media',
15
- access: {
16
- read: () => true,
17
- },
18
- fields: [
19
- {
20
- name: 'alt',
21
- type: 'text',
22
- required: true,
23
- },
24
- {
25
- name: 'caption',
26
- type: 'richText',
27
- required: false,
28
- editor: lexicalEditor({
29
- features: ({ defaultFeatures }) => {
30
- return defaultFeatures.filter((feature) => {
31
- return feature.key === 'paragraph' || feature.key === 'link';
32
- });
33
- },
34
- }),
35
- },
36
- ...(additionalFields ? additionalFields : []),
37
- ],
38
- upload: {
39
- staticDir: 'media',
40
- imageSizes: [
41
- // Original Size (for WebP & Avif)
42
- {
43
- name: 'webp',
44
- width: undefined,
45
- height: undefined,
46
- formatOptions: {
47
- format: 'webp',
48
- options: {
49
- quality: 80,
50
- },
51
- },
52
- },
53
- {
54
- name: 'avif',
55
- width: undefined,
56
- height: undefined,
57
- formatOptions: {
58
- format: 'avif',
59
- options: {
60
- quality: 80,
61
- },
62
- },
63
- },
64
- // Thumbnail Sizes
65
- {
66
- name: 'thumbnail',
67
- width: 400,
68
- height: 300,
69
- position: 'centre',
70
- },
71
- {
72
- name: 'thumbnail_webp',
73
- width: 400,
74
- height: 300,
75
- position: 'centre',
76
- formatOptions: {
77
- format: 'webp',
78
- options: {
79
- quality: 80,
80
- },
81
- },
82
- },
83
- {
84
- name: 'thumbnail_avif',
85
- width: 400,
86
- height: 300,
87
- position: 'centre',
88
- formatOptions: {
89
- format: 'avif',
90
- options: {
91
- quality: 80,
92
- },
93
- },
94
- },
95
- // Mobile Sizes
96
- {
97
- name: 'mobile',
98
- width: 768,
99
- height: undefined,
100
- },
101
- {
102
- name: 'mobile_webp',
103
- width: 768,
104
- height: undefined,
105
- formatOptions: {
106
- format: 'webp',
107
- options: {
108
- quality: 80,
109
- },
110
- },
111
- },
112
- {
113
- name: 'mobile_avif',
114
- width: 768,
115
- height: undefined,
116
- formatOptions: {
117
- format: 'avif',
118
- options: {
119
- quality: 80,
120
- },
121
- },
122
- },
123
- // Tablet Sizes
124
- {
125
- name: 'tablet',
126
- width: 1024,
127
- height: undefined,
128
- },
129
- {
130
- name: 'tablet_webp',
131
- width: 1024,
132
- height: undefined,
133
- formatOptions: {
134
- format: 'webp',
135
- options: {
136
- quality: 80,
137
- },
138
- },
139
- },
140
- {
141
- name: 'tablet_avif',
142
- width: 1024,
143
- height: undefined,
144
- formatOptions: {
145
- format: 'avif',
146
- options: {
147
- quality: 80,
148
- },
149
- },
150
- },
151
- ],
152
- },
153
- };
154
- };
@@ -1,56 +0,0 @@
1
- import type { CollectionConfig } from 'payload';
2
-
3
- /**
4
- * Redirects Collection Configuration
5
- * In favour of the native plugin for more granular control.
6
- *
7
- * TODO: Potential to add regex redirects here, i.e product-category/(.*)$ => /category/$1
8
- *
9
- * @constructor
10
- */
11
- export const Redirects = (overrides?: Partial<CollectionConfig>): CollectionConfig => {
12
- return {
13
- slug: 'redirects',
14
- admin: {
15
- useAsTitle: 'from',
16
- },
17
- fields: [
18
- {
19
- name: 'from',
20
- type: 'text',
21
- label: 'From URL',
22
- required: true,
23
- index: true,
24
- admin: {
25
- description: 'The URL you want to redirect from, ensure it starts with a /',
26
- },
27
- },
28
- {
29
- name: 'to',
30
- type: 'text',
31
- label: 'Destination URL',
32
- required: true,
33
- admin: {
34
- description:
35
- 'The URL you want to redirect to, can be a relative or absolute URL',
36
- },
37
- },
38
- {
39
- name: 'code',
40
- type: 'select',
41
- label: 'Redirect Code',
42
- required: true,
43
- defaultValue: '301',
44
- options: [
45
- { label: '301 - Permanent', value: '301' },
46
- { label: '302 - Temporary', value: '302' },
47
- { label: '307 - Temporary Redirect', value: '307' },
48
- { label: '308 - Permanent Redirect', value: '308' },
49
- { label: '410 - Content Deleted', value: '410' },
50
- { label: '451 - Unavailable For Legal Reasons', value: '451' },
51
- ],
52
- },
53
- ],
54
- ...(overrides ? overrides : {}),
55
- };
56
- };
package/src/common/SEO.ts DELETED
@@ -1,45 +0,0 @@
1
- import { Field } from 'payload';
2
- import { validateURL } from '../util/validation';
3
-
4
- /**
5
- * SEO Fields define the additional fields that appear
6
- * within the Payload SEO plugin.
7
- */
8
- export const SEOFields: Field[] = [
9
- {
10
- type: 'row',
11
- fields: [
12
- {
13
- name: 'private',
14
- type: 'checkbox',
15
- label: 'Private',
16
- defaultValue: false,
17
- admin: {
18
- width: '50%',
19
- description:
20
- 'Enable private mode to prevent robots from crawling the page or website. When enabled it will output <meta name="robots" content="noindex" /> on the frontend.',
21
- },
22
- },
23
- {
24
- name: 'canonicalURL',
25
- type: 'text',
26
- label: 'Canonical',
27
- admin: {
28
- width: '50%',
29
- description:
30
- 'A canonical URL is the version of a webpage chosen by search engines like Google as the main version when there are duplicates.',
31
- },
32
- validate: validateURL,
33
- },
34
- ],
35
- },
36
- {
37
- name: 'structuredData',
38
- type: 'json',
39
- label: 'Structured Data',
40
- admin: {
41
- description:
42
- 'Structured data is a standardized format for providing information about a page and classifying the page content. The site Schema.org contains a standardised list of markup that the major search engines — Google, Bing, Yahoo and Yandex — have collectively agreed to support.',
43
- },
44
- },
45
- ];
@@ -1,32 +0,0 @@
1
- import { PayloadHandler, PayloadRequest } from 'payload';
2
-
3
- /**
4
- * Find a document in the given collection by its slug.
5
- *
6
- * @param collection
7
- */
8
- export const findBySlug = (collection: string): PayloadHandler => {
9
- return async (req: PayloadRequest): Promise<Response> => {
10
- try {
11
- const data = await req.payload.find({
12
- collection,
13
- where: {
14
- slug: {
15
- equals: req.routeParams.slug,
16
- },
17
- },
18
- limit: 1,
19
- });
20
- if (data.docs.length === 0) {
21
- return new Response(JSON.stringify({ error: 'not found' }), { status: 404 });
22
- } else {
23
- return new Response(JSON.stringify(data.docs[0]), { status: 200 });
24
- }
25
- } catch (error) {
26
- console.error('Error occurred while fetching document:', error);
27
- return new Response(JSON.stringify({ error: 'Internal server error' }), {
28
- status: 500,
29
- });
30
- }
31
- };
32
- };