From 0655057ba3548fd89393805c44d562b2b8b0bce5 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 18 Sep 2023 13:15:37 +0300 Subject: [PATCH] Pagify --- apps/codeforafrica/src/lib/data/blockify/index.js | 2 +- apps/codeforafrica/src/lib/data/common/index.js | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/apps/codeforafrica/src/lib/data/blockify/index.js b/apps/codeforafrica/src/lib/data/blockify/index.js index 8b522d11e..289f084f9 100644 --- a/apps/codeforafrica/src/lib/data/blockify/index.js +++ b/apps/codeforafrica/src/lib/data/blockify/index.js @@ -6,7 +6,7 @@ const propsifyBlockBySlug = { async function blockify(blocks) { const promises = blocks?.map(async (block) => { - const slug = block.blockType; + const slug = block.blockType ?? block.slug ?? null; const propsifyBlock = propsifyBlockBySlug[slug]; if (propsifyBlock) { diff --git a/apps/codeforafrica/src/lib/data/common/index.js b/apps/codeforafrica/src/lib/data/common/index.js index ed4f555ac..407abd45a 100644 --- a/apps/codeforafrica/src/lib/data/common/index.js +++ b/apps/codeforafrica/src/lib/data/common/index.js @@ -48,27 +48,22 @@ function getPageSlug({ params }) { export async function getPageProps(api, context) { const { params } = context; const slug = getPageSlug(context); - const { + let { docs: [page], } = await api.findPage(slug); if (!page) { return null; } - let props; if (params?.slugs?.length > 2) { - props = await pagify(page, api, context); - } else { - const blocks = await blockify(page.blocks); - props = { - blocks, - }; + page = await pagify(page, api, context); } + const blocks = await blockify(page.blocks); const settings = await api.findGlobal("settings"); const navbar = getNavBar(settings); const footer = getFooter(settings); return { - ...props, + blocks, footer, navbar, };