@payloadcms/plugin-seo 3.0.0-beta.7 → 3.0.0-canary.0ff7f07

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 (42) hide show
  1. package/dist/exports/types.d.ts +2 -0
  2. package/dist/exports/types.d.ts.map +1 -0
  3. package/dist/exports/types.js +3 -0
  4. package/dist/exports/types.js.map +1 -0
  5. package/dist/fields/MetaDescription.d.ts.map +1 -1
  6. package/dist/fields/MetaDescription.js +90 -64
  7. package/dist/fields/MetaDescription.js.map +1 -1
  8. package/dist/fields/MetaImage.d.ts.map +1 -1
  9. package/dist/fields/MetaImage.js +91 -69
  10. package/dist/fields/MetaImage.js.map +1 -1
  11. package/dist/fields/MetaTitle.d.ts.map +1 -1
  12. package/dist/fields/MetaTitle.js +91 -64
  13. package/dist/fields/MetaTitle.js.map +1 -1
  14. package/dist/fields/index.scss +1 -1
  15. package/dist/index.d.ts +3 -4
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +53 -28
  18. package/dist/index.js.map +1 -1
  19. package/dist/translations/index.d.ts +25 -0
  20. package/dist/translations/index.d.ts.map +1 -1
  21. package/dist/translations/index.js +22 -0
  22. package/dist/translations/index.js.map +1 -1
  23. package/dist/translations/uk.json +22 -0
  24. package/dist/types.d.ts +5 -5
  25. package/dist/types.d.ts.map +1 -1
  26. package/dist/types.js.map +1 -1
  27. package/dist/ui/LengthIndicator.d.ts.map +1 -1
  28. package/dist/ui/LengthIndicator.js +61 -40
  29. package/dist/ui/LengthIndicator.js.map +1 -1
  30. package/dist/ui/Overview.d.ts.map +1 -1
  31. package/dist/ui/Overview.js +10 -6
  32. package/dist/ui/Overview.js.map +1 -1
  33. package/dist/ui/Pill.js +7 -3
  34. package/dist/ui/Pill.js.map +1 -1
  35. package/dist/ui/Preview.d.ts +1 -1
  36. package/dist/ui/Preview.d.ts.map +1 -1
  37. package/dist/ui/Preview.js +55 -34
  38. package/dist/ui/Preview.js.map +1 -1
  39. package/package.json +46 -31
  40. package/src/index.tsx +0 -293
  41. package/types.d.ts +0 -1
  42. package/types.js +0 -1
package/src/index.tsx DELETED
@@ -1,293 +0,0 @@
1
- import type { Config } from 'payload/config'
2
- import type { Field, GroupField, TabsField, TextField } from 'payload/types'
3
-
4
- import { deepMerge } from 'payload/utilities'
5
- import React from 'react'
6
-
7
- import type {
8
- GenerateDescription,
9
- GenerateImage,
10
- GenerateTitle,
11
- GenerateURL,
12
- PluginConfig,
13
- } from './types.js'
14
-
15
- import { MetaDescription } from './fields/MetaDescription.js'
16
- import { MetaImage } from './fields/MetaImage.js'
17
- import { MetaTitle } from './fields/MetaTitle.js'
18
- import { translations } from './translations/index.js'
19
- import { Overview } from './ui/Overview.js'
20
- import { Preview } from './ui/Preview.js'
21
-
22
- const seo =
23
- (pluginConfig: PluginConfig) =>
24
- (config: Config): Config => {
25
- const seoFields: GroupField[] = [
26
- {
27
- name: 'meta',
28
- type: 'group',
29
- fields: [
30
- {
31
- name: 'overview',
32
- type: 'ui',
33
- admin: {
34
- components: {
35
- Field: Overview,
36
- },
37
- },
38
- label: 'Overview',
39
- },
40
- {
41
- name: 'title',
42
- type: 'text',
43
- admin: {
44
- components: {
45
- Field: (props) => (
46
- <MetaTitle
47
- {...props}
48
- hasGenerateTitleFn={typeof pluginConfig.generateTitle === 'function'}
49
- />
50
- ),
51
- },
52
- },
53
- localized: true,
54
- ...((pluginConfig?.fieldOverrides?.title as unknown as TextField) ?? {}),
55
- },
56
- {
57
- name: 'description',
58
- type: 'textarea',
59
- admin: {
60
- components: {
61
- Field: (props) => (
62
- <MetaDescription
63
- {...props}
64
- hasGenerateDescriptionFn={
65
- typeof pluginConfig.generateDescription === 'function'
66
- }
67
- />
68
- ),
69
- },
70
- },
71
- localized: true,
72
- ...(pluginConfig?.fieldOverrides?.description ?? {}),
73
- },
74
- ...(pluginConfig?.uploadsCollection
75
- ? [
76
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
77
- {
78
- name: 'image',
79
- type: 'upload',
80
- admin: {
81
- components: {
82
- Field: (props) => (
83
- <MetaImage
84
- {...props}
85
- hasGenerateImageFn={typeof pluginConfig.generateImage === 'function'}
86
- />
87
- ),
88
- },
89
- description:
90
- 'Maximum upload file size: 12MB. Recommended file size for images is <500KB.',
91
- },
92
- label: 'Meta Image',
93
- localized: true,
94
- relationTo: pluginConfig?.uploadsCollection,
95
- ...(pluginConfig?.fieldOverrides?.image ?? {}),
96
- } as Field,
97
- ]
98
- : []),
99
- ...(pluginConfig?.fields || []),
100
- {
101
- name: 'preview',
102
- type: 'ui',
103
- admin: {
104
- components: {
105
- Field: (props) => (
106
- <Preview
107
- {...props}
108
- hasGenerateURLFn={typeof pluginConfig.generateURL === 'function'}
109
- />
110
- ),
111
- },
112
- },
113
- label: 'Preview',
114
- },
115
- ],
116
- interfaceName: pluginConfig.interfaceName,
117
- label: 'SEO',
118
- },
119
- ]
120
-
121
- return {
122
- ...config,
123
- collections:
124
- config.collections?.map((collection) => {
125
- const { slug } = collection
126
- const isEnabled = pluginConfig?.collections?.includes(slug)
127
-
128
- if (isEnabled) {
129
- if (pluginConfig?.tabbedUI) {
130
- // prevent issues with auth enabled collections having an email field that shouldn't be moved to the SEO tab
131
- const emailField =
132
- (collection.auth ||
133
- !(typeof collection.auth === 'object' && collection.auth.disableLocalStrategy)) &&
134
- collection.fields?.find((field) => 'name' in field && field.name === 'email')
135
- const hasOnlyEmailField = collection.fields?.length === 1 && emailField
136
-
137
- const seoTabs: TabsField[] = hasOnlyEmailField
138
- ? [
139
- {
140
- type: 'tabs',
141
- tabs: [
142
- {
143
- fields: seoFields,
144
- label: 'SEO',
145
- },
146
- ],
147
- },
148
- ]
149
- : [
150
- {
151
- type: 'tabs',
152
- tabs: [
153
- // append a new tab onto the end of the tabs array, if there is one at the first index
154
- // if needed, create a new `Content` tab in the first index for this collection's base fields
155
- ...(collection?.fields?.[0]?.type === 'tabs' &&
156
- collection?.fields?.[0]?.tabs
157
- ? collection.fields[0].tabs
158
- : [
159
- {
160
- fields: [
161
- ...(emailField
162
- ? collection.fields.filter(
163
- (field) => 'name' in field && field.name !== 'email',
164
- )
165
- : collection.fields),
166
- ],
167
- label: collection?.labels?.singular || 'Content',
168
- },
169
- ]),
170
- {
171
- fields: seoFields,
172
- label: 'SEO',
173
- },
174
- ],
175
- },
176
- ]
177
-
178
- return {
179
- ...collection,
180
- fields: [
181
- ...(emailField ? [emailField] : []),
182
- ...seoTabs,
183
- ...(collection?.fields?.[0]?.type === 'tabs' ? collection.fields.slice(1) : []),
184
- ],
185
- }
186
- }
187
-
188
- return {
189
- ...collection,
190
- fields: [...(collection?.fields || []), ...seoFields],
191
- }
192
- }
193
-
194
- return collection
195
- }) || [],
196
- endpoints: [
197
- {
198
- handler: async (req) => {
199
- const args: Parameters<GenerateTitle>[0] =
200
- req.data as unknown as Parameters<GenerateTitle>[0]
201
- const result = await pluginConfig.generateTitle(args)
202
- return new Response(JSON.stringify({ result }), { status: 200 })
203
- },
204
- method: 'post',
205
- path: '/plugin-seo/generate-title',
206
- },
207
- {
208
- handler: async (req) => {
209
- const args: Parameters<GenerateDescription>[0] =
210
- req.data as unknown as Parameters<GenerateDescription>[0]
211
- const result = await pluginConfig.generateDescription(args)
212
- return new Response(JSON.stringify({ result }), { status: 200 })
213
- },
214
- method: 'post',
215
- path: '/plugin-seo/generate-description',
216
- },
217
- {
218
- handler: async (req) => {
219
- const args: Parameters<GenerateURL>[0] =
220
- req.data as unknown as Parameters<GenerateURL>[0]
221
- const result = await pluginConfig.generateURL(args)
222
- return new Response(JSON.stringify({ result }), { status: 200 })
223
- },
224
- method: 'post',
225
- path: '/plugin-seo/generate-url',
226
- },
227
- {
228
- handler: async (req) => {
229
- const args: Parameters<GenerateImage>[0] =
230
- req.data as unknown as Parameters<GenerateImage>[0]
231
- const result = await pluginConfig.generateImage(args)
232
- return new Response(result, { status: 200 })
233
- },
234
- method: 'post',
235
- path: '/plugin-seo/generate-image',
236
- },
237
- ],
238
- globals:
239
- config.globals?.map((global) => {
240
- const { slug } = global
241
- const isEnabled = pluginConfig?.globals?.includes(slug)
242
-
243
- if (isEnabled) {
244
- if (pluginConfig?.tabbedUI) {
245
- const seoTabs: TabsField[] = [
246
- {
247
- type: 'tabs',
248
- tabs: [
249
- // append a new tab onto the end of the tabs array, if there is one at the first index
250
- // if needed, create a new `Content` tab in the first index for this global's base fields
251
- ...(global?.fields?.[0].type === 'tabs' && global?.fields?.[0].tabs
252
- ? global.fields[0].tabs
253
- : [
254
- {
255
- fields: [...(global?.fields || [])],
256
- label: global?.label || 'Content',
257
- },
258
- ]),
259
- {
260
- fields: seoFields,
261
- label: 'SEO',
262
- },
263
- ],
264
- },
265
- ]
266
-
267
- return {
268
- ...global,
269
- fields: [
270
- ...seoTabs,
271
- ...(global?.fields?.[0].type === 'tabs' ? global.fields.slice(1) : []),
272
- ],
273
- }
274
- }
275
-
276
- return {
277
- ...global,
278
- fields: [...(global?.fields || []), ...seoFields],
279
- }
280
- }
281
-
282
- return global
283
- }) || [],
284
- i18n: {
285
- ...config.i18n,
286
- translations: {
287
- ...deepMerge(translations, config.i18n?.translations),
288
- },
289
- },
290
- }
291
- }
292
-
293
- export { seo }
package/types.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './dist/types'
package/types.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./dist/types')