From 8233de7c5355f502eb335d00682c42e2f8dde456 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Wed, 2 Feb 2022 12:31:45 +0100 Subject: fix: handle getStaticPaths fallback I had errors with next build because of fallback. I need to return early if the path does not exists, if not Next complains about undefined variables. I don't think it was related but I also fix the paths format in getStaticPaths, I forgot the params object in some dynamic routes. --- src/utils/helpers/format.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/utils/helpers/format.ts') diff --git a/src/utils/helpers/format.ts b/src/utils/helpers/format.ts index e45a6a0..817daaf 100644 --- a/src/utils/helpers/format.ts +++ b/src/utils/helpers/format.ts @@ -1,3 +1,4 @@ +import { ParamsSlug, Slug } from '@ts/types/app'; import { Article, ArticlePreview, @@ -283,3 +284,14 @@ export const getFormattedDate = (date: string, locale: string) => { return new Date(date).toLocaleDateString(locale, dateOptions); }; + +/** + * Convert an array of slugs to an array of params with slug. + * @param {Slug} array - An array of object with slug. + * @returns {ParamsSlug} An array of params with slug. + */ +export const getFormattedPaths = (array: Slug[]): ParamsSlug[] => { + return array.map((object) => { + return { params: { slug: object.slug } }; + }); +}; -- cgit v1.2.3