Skip to content

Commit

Permalink
Fix SEO title and description
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinkipruto committed Sep 18, 2023
1 parent e01ab92 commit 4c48ad6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions apps/codeforafrica/src/lib/data/seo.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import site from "@/codeforafrica/utils/site";

function stringifyDescription(description) {
if (!description || !Array.isArray(description)) {
if (!Array.isArray(description)) {
return "";
}
let result = "";
description.forEach((item) => {
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;
return result;
}, "");
}

export default function getPageSeoFromMeta(page, settings) {
Expand All @@ -25,7 +26,12 @@ export default function getPageSeoFromMeta(page, settings) {
image = {},
} = pageMeta;
const { title: siteTitle, description: siteDescription } = settings;
const title = metaTitle || pageTitle || siteTitle || null;
const title =
metaTitle ||
pageTitle ||
siteTitle ||
process.env.NEXT_PUBLIC_APP_NAME ||
null;
const description =
metaDescription || stringifyDescription(siteDescription) || null;
const titleTemplate = siteTitle ? `%s | ${siteTitle}` : null;
Expand Down

0 comments on commit 4c48ad6

Please sign in to comment.