feat(cms-core): add Users, Articles, Media collections and SiteSettings global
This commit is contained in:
60
packages/cms-core/src/collections/articles/fields.ts
Normal file
60
packages/cms-core/src/collections/articles/fields.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import type { Field } from "payload";
|
||||
|
||||
export const articleFields: Field[] = [
|
||||
{
|
||||
name: "title",
|
||||
type: "text",
|
||||
required: true,
|
||||
maxLength: 255,
|
||||
},
|
||||
{
|
||||
name: "slug",
|
||||
type: "text",
|
||||
unique: true,
|
||||
admin: {
|
||||
position: "sidebar",
|
||||
description: "Auto-generated from title if left empty",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "content",
|
||||
type: "richText",
|
||||
},
|
||||
{
|
||||
name: "status",
|
||||
type: "select",
|
||||
options: [
|
||||
{ label: "Draft", value: "draft" },
|
||||
{ label: "Published", value: "published" },
|
||||
],
|
||||
defaultValue: "draft",
|
||||
required: true,
|
||||
admin: {
|
||||
position: "sidebar",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "author",
|
||||
type: "relationship",
|
||||
relationTo: "users",
|
||||
required: true,
|
||||
admin: {
|
||||
position: "sidebar",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "featuredImage",
|
||||
type: "upload",
|
||||
relationTo: "media",
|
||||
},
|
||||
{
|
||||
name: "publishedAt",
|
||||
type: "date",
|
||||
admin: {
|
||||
position: "sidebar",
|
||||
date: {
|
||||
pickerAppearance: "dayAndTime",
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { CollectionBeforeChangeHook } from "payload";
|
||||
|
||||
function generateSlug(title: string): string {
|
||||
return title
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-|-$/g, "");
|
||||
}
|
||||
|
||||
export const autoGenerateSlug: CollectionBeforeChangeHook = ({
|
||||
data,
|
||||
operation,
|
||||
}) => {
|
||||
if (operation === "create" || operation === "update") {
|
||||
if (data && data.title && !data.slug) {
|
||||
data.slug = generateSlug(data.title);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
};
|
||||
19
packages/cms-core/src/collections/articles/index.ts
Normal file
19
packages/cms-core/src/collections/articles/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { CollectionConfig } from "payload";
|
||||
|
||||
import { articleFields } from "./fields.js";
|
||||
import { autoGenerateSlug } from "./hooks/before-change.js";
|
||||
|
||||
export const Articles: CollectionConfig = {
|
||||
slug: "articles",
|
||||
admin: {
|
||||
useAsTitle: "title",
|
||||
defaultColumns: ["title", "status", "author", "updatedAt"],
|
||||
},
|
||||
hooks: {
|
||||
beforeChange: [autoGenerateSlug],
|
||||
},
|
||||
versions: {
|
||||
drafts: true,
|
||||
},
|
||||
fields: articleFields,
|
||||
};
|
||||
18
packages/cms-core/src/collections/media/index.ts
Normal file
18
packages/cms-core/src/collections/media/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { CollectionConfig } from "payload";
|
||||
|
||||
export const Media: CollectionConfig = {
|
||||
slug: "media",
|
||||
upload: {
|
||||
mimeTypes: ["image/*", "application/pdf"],
|
||||
},
|
||||
admin: {
|
||||
useAsTitle: "filename",
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: "alt",
|
||||
type: "text",
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
26
packages/cms-core/src/collections/users/index.ts
Normal file
26
packages/cms-core/src/collections/users/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { CollectionConfig } from "payload";
|
||||
|
||||
export const Users: CollectionConfig = {
|
||||
slug: "users",
|
||||
auth: true,
|
||||
admin: {
|
||||
useAsTitle: "email",
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: "displayName",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
name: "role",
|
||||
type: "select",
|
||||
options: [
|
||||
{ label: "Admin", value: "admin" },
|
||||
{ label: "Editor", value: "editor" },
|
||||
{ label: "Author", value: "author" },
|
||||
],
|
||||
defaultValue: "author",
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
20
packages/cms-core/src/globals/site-settings.ts
Normal file
20
packages/cms-core/src/globals/site-settings.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { GlobalConfig } from "payload";
|
||||
|
||||
export const SiteSettings: GlobalConfig = {
|
||||
slug: "site-settings",
|
||||
admin: {
|
||||
group: "Settings",
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: "siteName",
|
||||
type: "text",
|
||||
required: true,
|
||||
defaultValue: "My App",
|
||||
},
|
||||
{
|
||||
name: "siteDescription",
|
||||
type: "textarea",
|
||||
},
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user