♻️ Use keystonejs
This commit is contained in:
		
							
								
								
									
										41
									
								
								content/schema/assets.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								content/schema/assets.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| import { image, select, text, timestamp } from "@keystone-6/core/fields"; | ||||
| import { list } from "@keystone-6/core"; | ||||
|  | ||||
| import { allowEditor } from "../limit"; | ||||
|  | ||||
| export const Image = list({ | ||||
|   access: allowEditor, | ||||
|  | ||||
|   fields: { | ||||
|     caption: text(), | ||||
|     image: image({ storage: "localImages" }), | ||||
|  | ||||
|     createdAt: timestamp({ | ||||
|       defaultValue: { kind: "now" }, | ||||
|     }), | ||||
|   }, | ||||
| }); | ||||
|  | ||||
| export const Asset = list({ | ||||
|   access: allowEditor, | ||||
|  | ||||
|   fields: { | ||||
|     caption: text(), | ||||
|     url: text({ validation: { isRequired: true } }), | ||||
|     type: select({ | ||||
|       type: "enum", | ||||
|       options: [ | ||||
|         { label: "Video", value: "video" }, | ||||
|         { label: "Audio", value: "audio" }, | ||||
|       ], | ||||
|       defaultValue: "video", | ||||
|       db: { map: "media_type" }, | ||||
|       validation: { isRequired: true }, | ||||
|       ui: { displayMode: "select" }, | ||||
|     }), | ||||
|  | ||||
|     createdAt: timestamp({ | ||||
|       defaultValue: { kind: "now" }, | ||||
|     }), | ||||
|   }, | ||||
| }); | ||||
							
								
								
									
										37
									
								
								content/schema/categories.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								content/schema/categories.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| import { list } from "@keystone-6/core"; | ||||
| import { allowEditor } from "../limit"; | ||||
| import { relationship, text } from "@keystone-6/core/fields"; | ||||
|  | ||||
| export const Category = list({ | ||||
|   access: allowEditor, | ||||
|  | ||||
|   fields: { | ||||
|     slug: text({ | ||||
|       validation: { | ||||
|         isRequired: true, | ||||
|       }, | ||||
|       isIndexed: "unique", | ||||
|     }), | ||||
|     name: text(), | ||||
|     posts: relationship({ ref: "Post.categories", many: true }), | ||||
|     moments: relationship({ ref: "Moment.categories", many: true }), | ||||
|     events: relationship({ ref: "Event.categories", many: true }), | ||||
|   }, | ||||
| }); | ||||
|  | ||||
| export const Tag = list({ | ||||
|   access: allowEditor, | ||||
|  | ||||
|   fields: { | ||||
|     slug: text({ | ||||
|       validation: { | ||||
|         isRequired: true, | ||||
|       }, | ||||
|       isIndexed: "unique", | ||||
|     }), | ||||
|     name: text(), | ||||
|     posts: relationship({ ref: "Post.tags", many: true }), | ||||
|     moments: relationship({ ref: "Moment.tags", many: true }), | ||||
|     events: relationship({ ref: "Event.tags", many: true }), | ||||
|   }, | ||||
| }); | ||||
							
								
								
									
										94
									
								
								content/schema/events.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								content/schema/events.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,94 @@ | ||||
| import { | ||||
|   checkbox, | ||||
|   relationship, | ||||
|   text, | ||||
|   timestamp, | ||||
| } from "@keystone-6/core/fields"; | ||||
| import { document } from "@keystone-6/fields-document"; | ||||
| import { list } from "@keystone-6/core"; | ||||
| import { allowEditor } from "../limit"; | ||||
| import { Session } from "../auth"; | ||||
|  | ||||
| export const Event = list({ | ||||
|   access: { | ||||
|     ...allowEditor, | ||||
|  | ||||
|     filter: { | ||||
|       query: ({ session }: { session: Session }) => { | ||||
|         if (session?.data.isEditor || session?.data.isAdmin) return true; | ||||
|         return { isPublished: { equals: true } }; | ||||
|       }, | ||||
|     }, | ||||
|   }, | ||||
|  | ||||
|   fields: { | ||||
|     slug: text({ | ||||
|       validation: { | ||||
|         isRequired: true, | ||||
|       }, | ||||
|       isIndexed: "unique", | ||||
|     }), | ||||
|     title: text({ validation: { isRequired: true } }), | ||||
|     description: text(), | ||||
|  | ||||
|     content: document({ | ||||
|       formatting: true, | ||||
|       layouts: [ | ||||
|         [1, 1], | ||||
|         [1, 1, 1], | ||||
|         [2, 1], | ||||
|         [1, 2], | ||||
|         [1, 2, 1], | ||||
|       ], | ||||
|       links: true, | ||||
|       dividers: true, | ||||
|     }), | ||||
|  | ||||
|     isPublished: checkbox(), | ||||
|     isHistory: checkbox(), | ||||
|  | ||||
|     author: relationship({ | ||||
|       ref: "User.events", | ||||
|  | ||||
|       ui: { | ||||
|         displayMode: "cards", | ||||
|         cardFields: ["name", "email"], | ||||
|         inlineEdit: { fields: ["name", "email"] }, | ||||
|         linkToItem: true, | ||||
|         inlineConnect: true, | ||||
|       }, | ||||
|  | ||||
|       many: false, | ||||
|     }), | ||||
|  | ||||
|     categories: relationship({ | ||||
|       ref: "Category.events", | ||||
|       many: true, | ||||
|       ui: { | ||||
|         displayMode: "cards", | ||||
|         cardFields: ["name"], | ||||
|         inlineEdit: { fields: ["name"] }, | ||||
|         linkToItem: true, | ||||
|         inlineConnect: true, | ||||
|         inlineCreate: { fields: ["name"] }, | ||||
|       }, | ||||
|     }), | ||||
|  | ||||
|     tags: relationship({ | ||||
|       ref: "Tag.events", | ||||
|       many: true, | ||||
|       ui: { | ||||
|         displayMode: "cards", | ||||
|         cardFields: ["name"], | ||||
|         inlineEdit: { fields: ["name"] }, | ||||
|         linkToItem: true, | ||||
|         inlineConnect: true, | ||||
|         inlineCreate: { fields: ["name"] }, | ||||
|       }, | ||||
|     }), | ||||
|  | ||||
|     createdAt: timestamp({ | ||||
|       defaultValue: { kind: "now" }, | ||||
|     }), | ||||
|   }, | ||||
| }); | ||||
							
								
								
									
										55
									
								
								content/schema/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								content/schema/index.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| import { list } from "@keystone-6/core"; | ||||
|  | ||||
| import { | ||||
|   text, | ||||
|   relationship, | ||||
|   password, | ||||
|   timestamp, | ||||
|   checkbox, | ||||
| } from "@keystone-6/core/fields"; | ||||
|  | ||||
| import { allowAdmin } from "../limit"; | ||||
|  | ||||
| import { Image, Asset } from "./assets"; | ||||
| import { Moment } from "./moments"; | ||||
| import { Category, Tag } from "./categories"; | ||||
| import { Project } from "./projects"; | ||||
| import { Post } from "./posts"; | ||||
| import { Event } from "./events"; | ||||
|  | ||||
| export const lists = { | ||||
|   User: list({ | ||||
|     access: allowAdmin, | ||||
|  | ||||
|     fields: { | ||||
|       name: text({ validation: { isRequired: true } }), | ||||
|       email: text({ | ||||
|         validation: { isRequired: true }, | ||||
|         isIndexed: "unique", | ||||
|       }), | ||||
|  | ||||
|       password: password({ validation: { isRequired: true } }), | ||||
|       posts: relationship({ ref: "Post.author", many: true }), | ||||
|       moments: relationship({ ref: "Moment.author", many: true }), | ||||
|       events: relationship({ ref: "Event.author", many: true }), | ||||
|  | ||||
|       isAdmin: checkbox(), | ||||
|       isEditor: checkbox(), | ||||
|  | ||||
|       createdAt: timestamp({ | ||||
|         defaultValue: { kind: "now" }, | ||||
|       }), | ||||
|     }, | ||||
|   }), | ||||
|  | ||||
|   Image, | ||||
|   Asset, | ||||
|  | ||||
|   Post, | ||||
|   Moment, | ||||
|   Project, | ||||
|   Event, | ||||
|  | ||||
|   Category, | ||||
|   Tag, | ||||
| }; | ||||
							
								
								
									
										70
									
								
								content/schema/moments.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								content/schema/moments.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,70 @@ | ||||
| import { list } from "@keystone-6/core"; | ||||
| import { allowUser } from "../limit"; | ||||
| import { document } from "@keystone-6/fields-document"; | ||||
| import { relationship, text, timestamp } from "@keystone-6/core/fields"; | ||||
|  | ||||
| export const Moment = list({ | ||||
|     access: allowUser, | ||||
|  | ||||
|     fields: { | ||||
|       title: text({ validation: { isRequired: true } }), | ||||
|       images: relationship({ ref: "Image", many: true }), | ||||
|  | ||||
|       content: document({ | ||||
|         formatting: true, | ||||
|         layouts: [ | ||||
|           [1, 1], | ||||
|           [1, 1, 1], | ||||
|           [2, 1], | ||||
|           [1, 2], | ||||
|           [1, 2, 1], | ||||
|         ], | ||||
|         links: true, | ||||
|         dividers: true, | ||||
|       }), | ||||
|  | ||||
|       author: relationship({ | ||||
|         ref: "User.moments", | ||||
|  | ||||
|         ui: { | ||||
|           displayMode: "cards", | ||||
|           cardFields: ["name", "email"], | ||||
|           inlineEdit: { fields: ["name", "email"] }, | ||||
|           linkToItem: true, | ||||
|           inlineConnect: true, | ||||
|         }, | ||||
|  | ||||
|         many: false, | ||||
|       }), | ||||
|  | ||||
|       categories: relationship({ | ||||
|         ref: "Category.moments", | ||||
|         many: true, | ||||
|         ui: { | ||||
|           displayMode: "cards", | ||||
|           cardFields: ["name"], | ||||
|           inlineEdit: { fields: ["name"] }, | ||||
|           linkToItem: true, | ||||
|           inlineConnect: true, | ||||
|           inlineCreate: { fields: ["name"] }, | ||||
|         }, | ||||
|       }), | ||||
|  | ||||
|       tags: relationship({ | ||||
|         ref: "Tag.moments", | ||||
|         many: true, | ||||
|         ui: { | ||||
|           displayMode: "cards", | ||||
|           cardFields: ["name"], | ||||
|           inlineEdit: { fields: ["name"] }, | ||||
|           linkToItem: true, | ||||
|           inlineConnect: true, | ||||
|           inlineCreate: { fields: ["name"] }, | ||||
|         }, | ||||
|       }), | ||||
|  | ||||
|       createdAt: timestamp({ | ||||
|         defaultValue: { kind: "now" }, | ||||
|       }), | ||||
|     }, | ||||
|   }) | ||||
							
								
								
									
										110
									
								
								content/schema/posts.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								content/schema/posts.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,110 @@ | ||||
| import { | ||||
|   checkbox, | ||||
|   relationship, | ||||
|   select, | ||||
|   text, | ||||
|   timestamp, | ||||
| } from "@keystone-6/core/fields"; | ||||
| import { document } from "@keystone-6/fields-document"; | ||||
| import { list } from "@keystone-6/core"; | ||||
| import { allowEditor } from "../limit"; | ||||
| import { Session } from "../auth"; | ||||
|  | ||||
| export const Post = list({ | ||||
|   access: { | ||||
|     ...allowEditor, | ||||
|  | ||||
|     filter: { | ||||
|       query: ({ session }: { session: Session }) => { | ||||
|         if (session?.data.isEditor || session?.data.isAdmin) return true; | ||||
|         return { isPublished: { equals: true } }; | ||||
|       }, | ||||
|     }, | ||||
|   }, | ||||
|  | ||||
|   fields: { | ||||
|     slug: text({ | ||||
|       validation: { | ||||
|         isRequired: true, | ||||
|       }, | ||||
|       isIndexed: "unique", | ||||
|     }), | ||||
|     title: text({ validation: { isRequired: true } }), | ||||
|     cover: relationship({ ref: "Image" }), | ||||
|  | ||||
|     description: text(), | ||||
|  | ||||
|     assets: relationship({ ref: "Asset", many: true }), | ||||
|     images: relationship({ ref: "Image", many: true }), | ||||
|     content: document({ | ||||
|       formatting: true, | ||||
|       layouts: [ | ||||
|         [1, 1], | ||||
|         [1, 1, 1], | ||||
|         [2, 1], | ||||
|         [1, 2], | ||||
|         [1, 2, 1], | ||||
|       ], | ||||
|       links: true, | ||||
|       dividers: true, | ||||
|     }), | ||||
|  | ||||
|     type: select({ | ||||
|       type: "enum", | ||||
|       options: [ | ||||
|         { label: "Article", value: "article" }, | ||||
|         { label: "Podcast", value: "podcast" }, | ||||
|       ], | ||||
|       defaultValue: "article", | ||||
|       db: { map: "post_type" }, | ||||
|       validation: { isRequired: true }, | ||||
|       ui: { displayMode: "select" }, | ||||
|     }), | ||||
|  | ||||
|     isPublished: checkbox(), | ||||
|  | ||||
|     author: relationship({ | ||||
|       ref: "User.posts", | ||||
|  | ||||
|       ui: { | ||||
|         displayMode: "cards", | ||||
|         cardFields: ["name", "email"], | ||||
|         inlineEdit: { fields: ["name", "email"] }, | ||||
|         linkToItem: true, | ||||
|         inlineConnect: true, | ||||
|       }, | ||||
|  | ||||
|       many: false, | ||||
|     }), | ||||
|  | ||||
|     categories: relationship({ | ||||
|       ref: "Category.posts", | ||||
|       many: true, | ||||
|       ui: { | ||||
|         displayMode: "cards", | ||||
|         cardFields: ["name"], | ||||
|         inlineEdit: { fields: ["name"] }, | ||||
|         linkToItem: true, | ||||
|         inlineConnect: true, | ||||
|         inlineCreate: { fields: ["name"] }, | ||||
|       }, | ||||
|     }), | ||||
|  | ||||
|     tags: relationship({ | ||||
|       ref: "Tag.posts", | ||||
|       many: true, | ||||
|       ui: { | ||||
|         displayMode: "cards", | ||||
|         cardFields: ["name"], | ||||
|         inlineEdit: { fields: ["name"] }, | ||||
|         linkToItem: true, | ||||
|         inlineConnect: true, | ||||
|         inlineCreate: { fields: ["name"] }, | ||||
|       }, | ||||
|     }), | ||||
|  | ||||
|     createdAt: timestamp({ | ||||
|       defaultValue: { kind: "now" }, | ||||
|     }), | ||||
|   }, | ||||
| }); | ||||
							
								
								
									
										46
									
								
								content/schema/projects.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								content/schema/projects.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | ||||
| import { checkbox, relationship, select, text, timestamp } from "@keystone-6/core/fields"; | ||||
| import { list } from "@keystone-6/core"; | ||||
| import { allowAdmin } from "../limit"; | ||||
| import { Session } from "../auth"; | ||||
|  | ||||
| export const Project = list({ | ||||
|   access: { | ||||
|     ...allowAdmin, | ||||
|  | ||||
|     filter: { | ||||
|       query: ({ session }: { session: Session }) => { | ||||
|         if (session?.data.isEditor || session?.data.isAdmin) return true; | ||||
|         return { isPublished: { equals: true } }; | ||||
|       }, | ||||
|     }, | ||||
|   }, | ||||
|  | ||||
|   fields: { | ||||
|     icon: relationship({ ref: "Image" }), | ||||
|     name: text({ validation: { isRequired: true } }), | ||||
|     description: text(), | ||||
|     link: text(), | ||||
|  | ||||
|     isPublished: checkbox(), | ||||
|  | ||||
|     status: select({ | ||||
|       type: "enum", | ||||
|       options: [ | ||||
|         { label: "Pending", value: "pending" }, | ||||
|         { label: "Constructing", value: "constructing" }, | ||||
|         { label: "Published", value: "published" }, | ||||
|         { label: "Abandoned", value: "abandoned" }, | ||||
|       ], | ||||
|       defaultValue: "pending", | ||||
|       db: { map: "project_status" }, | ||||
|       validation: { isRequired: true }, | ||||
|       ui: { displayMode: "select" }, | ||||
|     }), | ||||
|  | ||||
|     post: relationship({ ref: "Post" }), | ||||
|  | ||||
|     createdAt: timestamp({ | ||||
|       defaultValue: { kind: "now" }, | ||||
|     }), | ||||
|   }, | ||||
| }); | ||||
		Reference in New Issue
	
	Block a user