Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft/codeforafrica posts setup #591

Merged
merged 15 commits into from
Sep 22, 2023
Merged
4 changes: 4 additions & 0 deletions apps/codeforafrica/payload.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import path from "path";

import { buildConfig } from "payload/config";
import Authors from "./src/payload/collections/Authors";
import GuidingPrinciples from "./src/payload/collections/GuidingPrinciples";
import Impact from "./src/payload/collections/Impact";
import Media from "./src/payload/collections/Media";
import Pages from "./src/payload/collections/Pages";
import Partners from "./src/payload/collections/Partners";
import Settings from "./src/payload/globals/Settings";
import Tags from "./src/payload/collections/Tags";
import { CollectionConfig, GlobalConfig } from "payload/types";
import dotenv from "dotenv";
import seo from "@payloadcms/plugin-seo";
Expand All @@ -33,11 +35,13 @@ const adapter = s3Adapter({
export default buildConfig({
serverURL: appURL,
collections: [
Authors,
GuidingPrinciples,
Impact,
Pages,
Media,
Partners,
Tags,
] as CollectionConfig[],
globals: [Settings] as GlobalConfig[],
admin: {
Expand Down
61 changes: 61 additions & 0 deletions apps/codeforafrica/src/payload/blocks/ExternalEmbed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import blockFields from "../fields/blockFields";

const ExternalEmbed = {
slug: "external-embed",
fields: [
blockFields({
name: "embedBlockFields",
fields: [
{
type: "row",
fields: [
{
name: "embedType",
type: "radio",
defaultValue: "url",
options: [
{
label: "URL",
value: "url",
},
{
label: "Code",
value: "code",
},
],
},
],
},
{
name: "url",
label: "URL",
type: "text",
required: true,
admin: {
condition: (_, siblingData) => siblingData?.embedType === "url",
},
},
{
name: "caption",
label: "Caption",
type: "text",
localized: true,
admin: {
condition: (_, siblingData) => siblingData?.embedType === "url",
},
},
{
name: "code",
label: "Code",
type: "code",
required: true,
admin: {
condition: (_, siblingData) => siblingData?.embedType === "code",
},
},
],
}),
],
};

export default ExternalEmbed;
23 changes: 23 additions & 0 deletions apps/codeforafrica/src/payload/blocks/MediaBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import blockFields from "../fields/blockFields";

const MediaBlock = {
slug: "mediaBlock",
fields: [
blockFields({
name: "mediaBlockFields",
fields: [
{
name: "image",
type: "upload",
relationTo: "media",
required: true,
filterOptions: {
mimeType: { contains: "image" },
},
},
],
}),
],
};

export default MediaBlock;
32 changes: 32 additions & 0 deletions apps/codeforafrica/src/payload/blocks/RichText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import blockFields from "../fields/blockFields";
import richText from "../fields/richText";

const RichText = {
slug: "richText",
fields: [
blockFields({
name: "richTextBlockFields",
fields: [
richText({
name: "content",
admin: {
elements: [
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"link",
"ol",
"ul",
"indent",
],
},
}),
],
}),
],
};

export default RichText;
20 changes: 20 additions & 0 deletions apps/codeforafrica/src/payload/collections/Authors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const Authors = {
slug: "author",
access: {
read: () => true,
},
admin: {
useAsTitle: "fullName",
},
fields: [
{
name: "fullName",
type: "text",
label: "Full Name",
localized: false,
required: true,
},
],
};

export default Authors;
24 changes: 24 additions & 0 deletions apps/codeforafrica/src/payload/collections/Tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import slug from "../fields/slug";

const Tags = {
slug: "tag",
admin: {
useAsTitle: "name",
},
access: {
read: () => true,
},
fields: [
{
name: "name",
label: "Name",
type: "text",
localized: true,
required: true,
unique: true,
},
slug({ fieldToUse: "name" }),
],
};

export default Tags;
17 changes: 17 additions & 0 deletions apps/codeforafrica/src/payload/fields/authors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { deepmerge } from "@mui/utils";

const authors = (overrides) =>
deepmerge(
{
name: "authors",
type: "relationship",
relationTo: "author",
hasMany: true,
admin: {
position: "sidebar",
},
},
overrides,
);

export default authors;
21 changes: 21 additions & 0 deletions apps/codeforafrica/src/payload/fields/blockFields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { deepmerge } from "@mui/utils";

const blockFields = ({ name, fields, overrides }) =>
deepmerge(
{
name,
label: false,
type: "group",
admin: {
hideGutter: true,
style: {
margin: 0,
padding: 0,
},
},
fields,
},
overrides,
);

export default blockFields;
18 changes: 18 additions & 0 deletions apps/codeforafrica/src/payload/fields/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { deepmerge } from "@mui/utils";

import ExternalEmbed from "../blocks/ExternalEmbed";
import MediaBlock from "../blocks/MediaBlock";
import RichText from "../blocks/RichText";

const content = (overrides) =>
deepmerge(
{
name: "content",
type: "blocks",
blocks: [RichText, MediaBlock, ExternalEmbed],
localized: true,
},
overrides,
);

export default content;
22 changes: 22 additions & 0 deletions apps/codeforafrica/src/payload/fields/publishedOn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { deepmerge } from "@mui/utils";

const publishedOn = (overrides) =>
deepmerge(
{
name: "publishedOn",
type: "date",
required: true,
hooks: {
beforeValidate: [({ value }) => (value ? new Date(value) : new Date())],
},
admin: {
date: {
pickerAppearance: "dayAndTime",
},
position: "sidebar",
},
},
overrides,
);

export default publishedOn;
14 changes: 14 additions & 0 deletions apps/codeforafrica/src/payload/fields/tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { deepmerge } from "@mui/utils";

const tags = (overrides) => {
const field = {
name: "tags",
required: true,
type: "relationship",
relationTo: "tag",
hasMany: true,
};
return deepmerge(field, overrides);
};

export default tags;
2 changes: 1 addition & 1 deletion apps/codeforafrica/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"build-next": {
"outputs": [".next/**", "!.next/cache/**", "dist/**"],
"env": []
"env": ["NEXT_PUBLIC_APP_NAME", "NEXT_PUBLIC_APP_URL"]
kelvinkipruto marked this conversation as resolved.
Show resolved Hide resolved
},
"build-payload": {
"outputs": ["build/**"],
Expand Down