-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/cfa-team-members
- Loading branch information
Showing
15 changed files
with
332 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import site from "@/codeforafrica/utils/site"; | ||
|
||
function stringifyDescription(description) { | ||
if (!Array.isArray(description)) { | ||
return ""; | ||
} | ||
return description.reduce((result, item) => { | ||
if (item.text) { | ||
// eslint-disable-next-line no-param-reassign | ||
result += item.text; | ||
} | ||
|
||
if (Array.isArray(item.children)) { | ||
// eslint-disable-next-line no-param-reassign | ||
result += stringifyDescription(item.children); | ||
} | ||
return result; | ||
}, ""); | ||
} | ||
|
||
export default function getPageSeoFromMeta(page, settings) { | ||
const { title: pageTitle, meta: pageMeta } = page; | ||
const { | ||
title: metaTitle, | ||
description: metaDescription, | ||
image = {}, | ||
} = pageMeta; | ||
const { title: siteTitle, description: siteDescription } = settings; | ||
const title = | ||
metaTitle || | ||
pageTitle || | ||
siteTitle || | ||
process.env.NEXT_PUBLIC_APP_NAME || | ||
null; | ||
const description = | ||
metaDescription || stringifyDescription(siteDescription) || null; | ||
const titleTemplate = siteTitle ? `%s | ${siteTitle}` : null; | ||
const defaultTitle = siteTitle || null; | ||
const canonical = site.url.replace(/\/+$/, ""); | ||
const openGraph = { | ||
title, | ||
description, | ||
type: "website", | ||
site_name: siteTitle, | ||
}; | ||
if (image.url) { | ||
const { alt, height, mimeType: type, url, width } = image; | ||
openGraph.images = [ | ||
{ | ||
alt: alt || title || defaultTitle, | ||
height, | ||
type, | ||
url, | ||
width, | ||
}, | ||
]; | ||
} | ||
|
||
return { | ||
title, | ||
titleTemplate, | ||
defaultTitle, | ||
description, | ||
canonical, | ||
openGraph, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.