Skip to content

Commit

Permalink
fix: handle empty resources and improve FAQ data mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Koech authored and Kevin Koech committed Jan 28, 2025
1 parent 3f1947a commit a0d83f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
18 changes: 10 additions & 8 deletions apps/promisetracker/src/lib/wp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function wp(site) {
});
const resource = resources[0];
if (isEmpty(resource)) {
return undefined;
return null;
}

/* eslint no-underscore-dangle: off */
Expand Down Expand Up @@ -349,13 +349,15 @@ function wp(site) {
pageWithPosts = page;
}
const posts =
pageWithPosts?.posts?.map((post) => ({
image: post.thumbnail_image,
description: post.content.replace(/(<([^>]+)>)/gi, ""),
date: formatDate(post.date),
slug: post.slug,
title: post.title,
})) || null;
pageWithPosts?.posts
?.filter((post) => !!post)
?.map((post) => ({
image: post.thumbnail_image,
description: post.content.replace(/(<([^>]+)>)/gi, ""),
date: formatDate(post.date),
slug: post.slug,
title: post.title,
})) || null;
return posts;
})();
},
Expand Down
7 changes: 4 additions & 3 deletions apps/promisetracker/src/pages/faq.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ export async function getStaticProps({ locale }) {
const backend = backendFn();
const site = await backend.sites().current;
const page = await wp().pages({ slug: "faq", locale }).first;
const faqs = page.faqs
.reduce((arr, e) => arr.concat(e.questions_answers), [])
.map((faq) => ({ title: faq.question, summary: faq.answer }));
const faqs =
page?.faqs
?.reduce((arr, e) => arr.concat(e.questions_answers), [])
?.map((faq) => ({ title: faq.question, summary: faq.answer })) ?? [];
const languageAlternates = _.languageAlternates("/faq");

return {
Expand Down

0 comments on commit a0d83f8

Please sign in to comment.