@ainsleydev/payload-helper 0.0.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/README.md +16 -0
- package/eslint.config.mjs +4 -0
- package/package.json +40 -0
- package/src/collections/Media.ts +149 -0
- package/src/collections/Redirects.ts +58 -0
- package/src/common/SEO.ts +45 -0
- package/src/endpoints/slug.ts +30 -0
- package/src/gen/schema.ts +584 -0
- package/src/globals/Navigation.ts +165 -0
- package/src/globals/Settings.ts +356 -0
- package/src/globals/countries.ts +196 -0
- package/src/globals/locales.ts +2668 -0
- package/src/scripts/.gitkeep +0 -0
- package/src/seed/.gitkeep +0 -0
- package/src/util/env.ts +96 -0
- package/src/util/validation.ts +24 -0
- package/tsconfig.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
## Payload Helper
|
|
2
|
+
|
|
3
|
+
Payload Helper is a project designed to extend and enhance functionality for Payload CMS. This
|
|
4
|
+
project includes custom configurations, scripts, and utilities to streamline development and content
|
|
5
|
+
management processes.
|
|
6
|
+
|
|
7
|
+
## Open Source
|
|
8
|
+
|
|
9
|
+
ainsley.dev permits the use of any HTML, SCSS and Javascript found within the repository for use
|
|
10
|
+
with external projects.
|
|
11
|
+
|
|
12
|
+
## Trademark
|
|
13
|
+
|
|
14
|
+
ainsley.dev and the ainsley.dev logo are either registered trademarks or trademarks of ainsley.dev
|
|
15
|
+
LTD in the United Kingdom and/or other countries. All other trademarks are the property of their
|
|
16
|
+
respective owners.
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ainsleydev/payload-helper",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Payload CMS utilities, collections and global types for ainsley.dev builds",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"payload",
|
|
8
|
+
"payloadcms",
|
|
9
|
+
"cms",
|
|
10
|
+
"utilities"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/ainsleydev/webkit.git",
|
|
15
|
+
"directory": "packages/payload-helper"
|
|
16
|
+
},
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "ainsley.dev",
|
|
19
|
+
"email": "hello@ainsley.dev",
|
|
20
|
+
"url": "https://ainsley.dev"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"publish": "npm publish --access public",
|
|
24
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@nouance/payload-better-fields-plugin": "^1.4.1",
|
|
28
|
+
"@payloadcms/richtext-slate": "^1.5.2",
|
|
29
|
+
"json-schema": "^0.4.0",
|
|
30
|
+
"payload": "^2.18.3",
|
|
31
|
+
"pluralize": "^8.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@ainsleydev/eslint-config": "workspace:*"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18",
|
|
38
|
+
"pnpm": ">=9"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// import { slateEditor } from '@payloadcms/richtext-slate';
|
|
2
|
+
import type { CollectionConfig, Field } from 'payload/types';
|
|
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 = (filePath: string, additionalFields?: Field[]): CollectionConfig => {
|
|
13
|
+
return {
|
|
14
|
+
slug: 'media',
|
|
15
|
+
upload: {
|
|
16
|
+
staticURL: '/media',
|
|
17
|
+
staticDir: filePath,
|
|
18
|
+
imageSizes: [
|
|
19
|
+
// Original Size (for WebP & Avif)
|
|
20
|
+
{
|
|
21
|
+
name: 'webp',
|
|
22
|
+
width: undefined,
|
|
23
|
+
height: undefined,
|
|
24
|
+
formatOptions: {
|
|
25
|
+
format: 'webp',
|
|
26
|
+
options: {
|
|
27
|
+
quality: 80,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'avif',
|
|
33
|
+
width: undefined,
|
|
34
|
+
height: undefined,
|
|
35
|
+
formatOptions: {
|
|
36
|
+
format: 'avif',
|
|
37
|
+
options: {
|
|
38
|
+
quality: 80,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
// Thumbnail Sizes
|
|
43
|
+
{
|
|
44
|
+
name: 'thumbnail',
|
|
45
|
+
width: 400,
|
|
46
|
+
height: 300,
|
|
47
|
+
position: 'centre',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'thumbnail_webp',
|
|
51
|
+
width: 400,
|
|
52
|
+
height: 300,
|
|
53
|
+
position: 'centre',
|
|
54
|
+
formatOptions: {
|
|
55
|
+
format: 'webp',
|
|
56
|
+
options: {
|
|
57
|
+
quality: 80,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'thumbnail_avif',
|
|
63
|
+
width: 400,
|
|
64
|
+
height: 300,
|
|
65
|
+
position: 'centre',
|
|
66
|
+
formatOptions: {
|
|
67
|
+
format: 'avif',
|
|
68
|
+
options: {
|
|
69
|
+
quality: 80,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
// Mobile Sizes
|
|
74
|
+
{
|
|
75
|
+
name: 'mobile',
|
|
76
|
+
width: 768,
|
|
77
|
+
height: undefined,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'mobile_webp',
|
|
81
|
+
width: 768,
|
|
82
|
+
height: undefined,
|
|
83
|
+
formatOptions: {
|
|
84
|
+
format: 'webp',
|
|
85
|
+
options: {
|
|
86
|
+
quality: 80,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'mobile_avif',
|
|
92
|
+
width: 768,
|
|
93
|
+
height: undefined,
|
|
94
|
+
formatOptions: {
|
|
95
|
+
format: 'avif',
|
|
96
|
+
options: {
|
|
97
|
+
quality: 80,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
// Tablet Sizes
|
|
102
|
+
{
|
|
103
|
+
name: 'tablet',
|
|
104
|
+
width: 1024,
|
|
105
|
+
height: undefined,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'tablet_webp',
|
|
109
|
+
width: 1024,
|
|
110
|
+
height: undefined,
|
|
111
|
+
formatOptions: {
|
|
112
|
+
format: 'webp',
|
|
113
|
+
options: {
|
|
114
|
+
quality: 80,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'tablet_avif',
|
|
120
|
+
width: 1024,
|
|
121
|
+
height: undefined,
|
|
122
|
+
formatOptions: {
|
|
123
|
+
format: 'avif',
|
|
124
|
+
options: {
|
|
125
|
+
quality: 80,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
fields: [
|
|
132
|
+
{
|
|
133
|
+
name: 'alt',
|
|
134
|
+
type: 'text',
|
|
135
|
+
required: true,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: 'caption',
|
|
139
|
+
type: 'richText',
|
|
140
|
+
// editor: slateEditor({
|
|
141
|
+
// admin: {
|
|
142
|
+
// elements: ['link'],
|
|
143
|
+
// },
|
|
144
|
+
// }),
|
|
145
|
+
},
|
|
146
|
+
...(additionalFields ? additionalFields : []),
|
|
147
|
+
],
|
|
148
|
+
};
|
|
149
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CollectionConfig } from 'payload/types';
|
|
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
|
+
...{
|
|
14
|
+
slug: 'redirects',
|
|
15
|
+
admin: {
|
|
16
|
+
useAsTitle: 'from',
|
|
17
|
+
},
|
|
18
|
+
fields: [
|
|
19
|
+
{
|
|
20
|
+
name: 'from',
|
|
21
|
+
type: 'text',
|
|
22
|
+
label: 'From URL',
|
|
23
|
+
required: true,
|
|
24
|
+
index: true,
|
|
25
|
+
admin: {
|
|
26
|
+
description: 'The URL you want to redirect from, ensure it starts with a /',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'to',
|
|
31
|
+
type: 'text',
|
|
32
|
+
label: 'Destination URL',
|
|
33
|
+
required: true,
|
|
34
|
+
admin: {
|
|
35
|
+
description:
|
|
36
|
+
'The URL you want to redirect to, can be a relative or absolute URL',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'code',
|
|
41
|
+
type: 'select',
|
|
42
|
+
label: 'Redirect Code',
|
|
43
|
+
required: true,
|
|
44
|
+
defaultValue: '301',
|
|
45
|
+
options: [
|
|
46
|
+
{ label: '301 - Permanent', value: '301' },
|
|
47
|
+
{ label: '302 - Temporary', value: '302' },
|
|
48
|
+
{ label: '307 - Temporary Redirect', value: '307' },
|
|
49
|
+
{ label: '308 - Permanent Redirect', value: '308' },
|
|
50
|
+
{ label: '410 - Content Deleted', value: '410' },
|
|
51
|
+
{ label: '451 - Unavailable For Legal Reasons', value: '451' },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
...(overrides ? overrides : {}),
|
|
57
|
+
};
|
|
58
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Field } from 'payload/types';
|
|
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
|
+
];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PayloadHandler } from 'payload/config';
|
|
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, res) => {
|
|
10
|
+
try {
|
|
11
|
+
const data = await req.payload.find({
|
|
12
|
+
collection,
|
|
13
|
+
where: {
|
|
14
|
+
slug: {
|
|
15
|
+
equals: req.params.slug,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
limit: 1,
|
|
19
|
+
});
|
|
20
|
+
if (data.docs.length === 0) {
|
|
21
|
+
res.status(404).send({ error: 'not found' });
|
|
22
|
+
} else {
|
|
23
|
+
res.status(200).send(data.docs[0]);
|
|
24
|
+
}
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error('Error occurred while fetching document:', error);
|
|
27
|
+
res.status(500).send({ error: 'Internal server error' });
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|