-
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 'ft/codeforafrica-posts-cms' into ft/codeforafrica-stori…
…es-cms Signed-off-by: Kipruto <[email protected]>
- Loading branch information
Showing
6 changed files
with
75 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
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