From d27e33061199dbc7650801735f9b7a99b31557e5 Mon Sep 17 00:00:00 2001 From: William Grant Date: Sat, 11 Dec 2021 08:16:53 +1100 Subject: [PATCH] fix for static tag page generation --- pages/tag/[...slug].tsx | 4 ++-- services/cms.tsx | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pages/tag/[...slug].tsx b/pages/tag/[...slug].tsx index 07868cf..304ecd9 100644 --- a/pages/tag/[...slug].tsx +++ b/pages/tag/[...slug].tsx @@ -186,8 +186,8 @@ export const getStaticPaths: GetStaticPaths = async () => { const pageCount = Math.ceil(total / CMS.BLOG_RESULTS_PER_PAGE); const _paths = []; - for (let i = 1; i <= pageCount; i++) { - _paths.push({ params: { slug: [tags[i], String(i)] } }); + for (let j = 1; j <= pageCount; j++) { + _paths.push({ params: { slug: [tags[i], String(j)] } }); } paths.push(..._paths); diff --git a/services/cms.tsx b/services/cms.tsx index e50e065..b15f4e8 100644 --- a/services/cms.tsx +++ b/services/cms.tsx @@ -86,11 +86,15 @@ export class CmsApi { skip: (page - 1) * quantity, }); - const results = await this.generateEntries(_entries, 'post'); - return { - entries: results.entries as Array, - total: results.total, - }; + if (_entries.items.length > 0) { + const results = await this.generateEntries(_entries, 'post'); + return { + entries: results.entries as Array, + total: results.total, + }; + } + + return Promise.reject(new Error(`Failed to fetch entries for ${tag}`)); } public async fetchBlogEntriesWithoutDevUpdates(