Compare commits
1 Commits
build/bump
...
test/relat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
259363e069 |
58
test/_community/collections/Authors/index.ts
Normal file
58
test/_community/collections/Authors/index.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import type { CollectionConfig } from 'payload'
|
||||
|
||||
const contentfulDefaultFields: CollectionConfig['fields'] = [
|
||||
{
|
||||
name: 'isFromContentful',
|
||||
type: 'checkbox',
|
||||
label: 'Is From Contentful (migration use only)',
|
||||
hidden: true,
|
||||
},
|
||||
{
|
||||
name: 'noIndex',
|
||||
type: 'checkbox',
|
||||
label: 'No Index',
|
||||
},
|
||||
{
|
||||
name: 'originalContentfulId',
|
||||
type: 'text',
|
||||
label: 'The original contentful ID of this item (migration use only)',
|
||||
},
|
||||
]
|
||||
|
||||
export const Authors: CollectionConfig = {
|
||||
slug: 'authors',
|
||||
admin: {
|
||||
useAsTitle: 'name',
|
||||
},
|
||||
versions: {
|
||||
drafts: true,
|
||||
maxPerDoc: 0, // Removes the limit on the number of versions we can store
|
||||
},
|
||||
access: {
|
||||
read: () => true,
|
||||
create: () => true,
|
||||
update: () => true,
|
||||
delete: () => true,
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'name',
|
||||
type: 'text',
|
||||
label: 'Name',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'avatar',
|
||||
type: 'upload',
|
||||
relationTo: 'media',
|
||||
label: 'Avatar',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'biography',
|
||||
type: 'richText',
|
||||
label: 'Biography',
|
||||
},
|
||||
...contentfulDefaultFields,
|
||||
],
|
||||
}
|
||||
@@ -1,28 +1,81 @@
|
||||
import type { CollectionConfig } from 'payload'
|
||||
export const contentfulDefaultFields: CollectionConfig['fields'] = [
|
||||
{
|
||||
name: 'isFromContentful',
|
||||
type: 'checkbox',
|
||||
label: 'Is From Contentful (migration use only)',
|
||||
hidden: true,
|
||||
},
|
||||
{
|
||||
name: 'noIndex',
|
||||
type: 'checkbox',
|
||||
label: 'No Index',
|
||||
},
|
||||
{
|
||||
name: 'originalContentfulId',
|
||||
type: 'text',
|
||||
label: 'The original contentful ID of this item (migration use only)',
|
||||
},
|
||||
]
|
||||
|
||||
import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
||||
|
||||
export const postsSlug = 'posts'
|
||||
|
||||
export const PostsCollection: CollectionConfig = {
|
||||
slug: postsSlug,
|
||||
export const ChangelogPosts: CollectionConfig = {
|
||||
slug: 'changelog-posts',
|
||||
admin: {
|
||||
useAsTitle: 'title',
|
||||
},
|
||||
versions: {
|
||||
drafts: true,
|
||||
maxPerDoc: 0, // Removes the limit on the number of versions we can store
|
||||
},
|
||||
access: {
|
||||
read: () => true,
|
||||
create: () => true,
|
||||
update: () => true,
|
||||
delete: () => true,
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
type: 'text',
|
||||
label: 'Title',
|
||||
required: true,
|
||||
localized: true,
|
||||
},
|
||||
{
|
||||
name: 'slug',
|
||||
type: 'text',
|
||||
label: 'Slug',
|
||||
required: true,
|
||||
index: true,
|
||||
},
|
||||
{
|
||||
name: 'publishDate',
|
||||
type: 'date',
|
||||
label: 'Publish Date',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'author',
|
||||
type: 'relationship',
|
||||
label: 'Author',
|
||||
required: true,
|
||||
relationTo: 'authors',
|
||||
hasMany: true,
|
||||
},
|
||||
{
|
||||
name: 'featuredImage',
|
||||
type: 'upload',
|
||||
label: 'Featured Image',
|
||||
required: true,
|
||||
relationTo: 'media',
|
||||
},
|
||||
{
|
||||
name: 'content',
|
||||
type: 'richText',
|
||||
editor: lexicalEditor({
|
||||
features: ({ defaultFeatures }) => [...defaultFeatures],
|
||||
}),
|
||||
label: 'Content',
|
||||
required: true,
|
||||
localized: true,
|
||||
},
|
||||
...contentfulDefaultFields,
|
||||
],
|
||||
versions: {
|
||||
drafts: true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@ import path from 'path'
|
||||
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
|
||||
import { devUser } from '../credentials.js'
|
||||
import { Authors } from './collections/Authors/index.js'
|
||||
import { MediaCollection } from './collections/Media/index.js'
|
||||
import { PostsCollection, postsSlug } from './collections/Posts/index.js'
|
||||
import { ChangelogPosts } from './collections/Posts/index.js'
|
||||
import { MenuGlobal } from './globals/Menu/index.js'
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
@@ -13,7 +14,7 @@ const dirname = path.dirname(filename)
|
||||
|
||||
export default buildConfigWithDefaults({
|
||||
// ...extend config here
|
||||
collections: [PostsCollection, MediaCollection],
|
||||
collections: [Authors, ChangelogPosts, MediaCollection],
|
||||
admin: {
|
||||
importMap: {
|
||||
baseDir: path.resolve(dirname),
|
||||
@@ -32,13 +33,6 @@ export default buildConfigWithDefaults({
|
||||
password: devUser.password,
|
||||
},
|
||||
})
|
||||
|
||||
await payload.create({
|
||||
collection: postsSlug,
|
||||
data: {
|
||||
title: 'example post',
|
||||
},
|
||||
})
|
||||
},
|
||||
typescript: {
|
||||
outputFile: path.resolve(dirname, 'payload-types.ts'),
|
||||
|
||||
@@ -11,7 +11,8 @@ export interface Config {
|
||||
users: UserAuthOperations;
|
||||
};
|
||||
collections: {
|
||||
posts: Post;
|
||||
authors: Author;
|
||||
'changelog-posts': ChangelogPost;
|
||||
media: Media;
|
||||
users: User;
|
||||
'payload-locked-documents': PayloadLockedDocument;
|
||||
@@ -20,7 +21,8 @@ export interface Config {
|
||||
};
|
||||
collectionsJoins: {};
|
||||
collectionsSelect: {
|
||||
posts: PostsSelect<false> | PostsSelect<true>;
|
||||
authors: AuthorsSelect<false> | AuthorsSelect<true>;
|
||||
'changelog-posts': ChangelogPostsSelect<false> | ChangelogPostsSelect<true>;
|
||||
media: MediaSelect<false> | MediaSelect<true>;
|
||||
users: UsersSelect<false> | UsersSelect<true>;
|
||||
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
|
||||
@@ -65,12 +67,13 @@ export interface UserAuthOperations {
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "posts".
|
||||
* via the `definition` "authors".
|
||||
*/
|
||||
export interface Post {
|
||||
export interface Author {
|
||||
id: string;
|
||||
title?: string | null;
|
||||
content?: {
|
||||
name: string;
|
||||
avatar: string | Media;
|
||||
biography?: {
|
||||
root: {
|
||||
type: string;
|
||||
children: {
|
||||
@@ -85,6 +88,9 @@ export interface Post {
|
||||
};
|
||||
[k: string]: unknown;
|
||||
} | null;
|
||||
isFromContentful?: boolean | null;
|
||||
noIndex?: boolean | null;
|
||||
originalContentfulId?: string | null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
_status?: ('draft' | 'published') | null;
|
||||
@@ -133,6 +139,39 @@ export interface Media {
|
||||
};
|
||||
};
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "changelog-posts".
|
||||
*/
|
||||
export interface ChangelogPost {
|
||||
id: string;
|
||||
title: string;
|
||||
slug: string;
|
||||
publishDate: string;
|
||||
author: (string | Author)[];
|
||||
featuredImage: string | Media;
|
||||
content: {
|
||||
root: {
|
||||
type: string;
|
||||
children: {
|
||||
type: string;
|
||||
version: number;
|
||||
[k: string]: unknown;
|
||||
}[];
|
||||
direction: ('ltr' | 'rtl') | null;
|
||||
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
|
||||
indent: number;
|
||||
version: number;
|
||||
};
|
||||
[k: string]: unknown;
|
||||
};
|
||||
isFromContentful?: boolean | null;
|
||||
noIndex?: boolean | null;
|
||||
originalContentfulId?: string | null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
_status?: ('draft' | 'published') | null;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "users".
|
||||
@@ -158,8 +197,12 @@ export interface PayloadLockedDocument {
|
||||
id: string;
|
||||
document?:
|
||||
| ({
|
||||
relationTo: 'posts';
|
||||
value: string | Post;
|
||||
relationTo: 'authors';
|
||||
value: string | Author;
|
||||
} | null)
|
||||
| ({
|
||||
relationTo: 'changelog-posts';
|
||||
value: string | ChangelogPost;
|
||||
} | null)
|
||||
| ({
|
||||
relationTo: 'media';
|
||||
@@ -213,11 +256,33 @@ export interface PayloadMigration {
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "posts_select".
|
||||
* via the `definition` "authors_select".
|
||||
*/
|
||||
export interface PostsSelect<T extends boolean = true> {
|
||||
export interface AuthorsSelect<T extends boolean = true> {
|
||||
name?: T;
|
||||
avatar?: T;
|
||||
biography?: T;
|
||||
isFromContentful?: T;
|
||||
noIndex?: T;
|
||||
originalContentfulId?: T;
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
_status?: T;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "changelog-posts_select".
|
||||
*/
|
||||
export interface ChangelogPostsSelect<T extends boolean = true> {
|
||||
title?: T;
|
||||
slug?: T;
|
||||
publishDate?: T;
|
||||
author?: T;
|
||||
featuredImage?: T;
|
||||
content?: T;
|
||||
isFromContentful?: T;
|
||||
noIndex?: T;
|
||||
originalContentfulId?: T;
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
_status?: T;
|
||||
|
||||
Reference in New Issue
Block a user