Initial commit

This commit is contained in:
Autonomic Cooperative
2024-05-17 22:32:32 +00:00
commit d07472434f
43 changed files with 12506 additions and 0 deletions

View File

@ -0,0 +1,25 @@
import { CollectionConfig } from "payload/types";
export const Media: CollectionConfig = {
slug: "media",
admin: {},
access: {
read: (): boolean => true,
create: () => true,
update: () => true,
},
upload: {
staticURL: "/media",
staticDir: "media",
mimeTypes: ["image/*"],
},
fields: [
{
name: "alt",
type: "text",
},
],
};
export default Media;

View File

@ -0,0 +1,98 @@
import { CollectionConfig } from "payload/types";
const Posts: CollectionConfig = {
slug: "posts",
admin: {
defaultColumns: ["title", "author", "status"],
useAsTitle: "title",
},
access: {
read: () => true,
create: () => true,
update: () => true,
},
hooks: {
afterChange: [
async () => {
console.log(process.env.TOKEN);
try {
process.env.NODE_ENV !== "development" &&
console.log(
await fetch(
`https://api.github.com/repos/${process.env.REPOSITORY}/dispatches`,
{
method: "POST",
headers: {
Accept: "application/vnd.github.everest-preview+json",
Authorization: `token ${process.env.TOKEN}`,
},
body: JSON.stringify({
event_type: "payload_update",
}),
}
)
);
} catch (e) {
console.log(e);
}
},
],
},
fields: [
{
name: "title",
type: "text",
},
{
name: "hallo",
type: "text",
},
{
name: "publishedDate",
type: "date",
},
{
name: "content",
type: "richText",
admin: {
elements: ["h2", "h3", "h4", "link", "ol", "ul", "upload"],
leaves: ["bold", "italic", "underline"],
upload: {
collections: {
media: {
fields: [
{
name: "imagel",
type: "upload",
relationTo: "media",
required: true,
},
],
},
},
},
},
},
{
name: "status",
type: "select",
options: [
{
value: "draft",
label: "Draft",
},
{
value: "published",
label: "Published",
},
],
defaultValue: "draft",
admin: {
position: "sidebar",
},
},
],
};
export default Posts;

View File

@ -0,0 +1,21 @@
import { CollectionConfig } from 'payload/types';
const Users: CollectionConfig = {
slug: 'users',
auth: true,
admin: {
useAsTitle: 'email',
},
access: {
read: () => true,
},
fields: [
// Email added by default
{
name: 'name',
type: 'text',
}
],
};
export default Users;

View File

@ -0,0 +1,26 @@
import { buildConfig } from "payload/config";
import path from "path";
import Posts from "@/collections/Posts";
import Users from "@/collections/Users";
import Media from "@/collections/Media";
export default buildConfig({
serverURL: process.env.PAYLOAD_URL,
admin: {
user: Users.slug,
webpack: (config) => ({
...config,
resolve: {
...config.resolve,
alias: {
...config.resolve.alias,
"@": path.resolve(__dirname, "./"),
},
},
}),
},
collections: [Posts, Users, Media],
typescript: {
outputFile: path.resolve("/", "types.ts"),
},
});

21
payload/src/server.ts Normal file
View File

@ -0,0 +1,21 @@
import express from "express";
import payload from "payload";
require("dotenv").config();
const app = express();
app.get("/", (_, res) => {
res.redirect("/admin");
});
payload.init({
secret: process.env.PAYLOAD_SECRET,
mongoURL: process.env.MONGODB_URI,
express: app,
onInit: () => {
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
},
});
app.use("/media", express.static("media"));
app.listen(process.env.PAYLOAD_PORT);