diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-02-02 12:31:45 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-02-02 12:31:45 +0100 |
| commit | 8233de7c5355f502eb335d00682c42e2f8dde456 (patch) | |
| tree | f7988b8967a0ce53e20c3dabd08c7f3c37bdbf1d /src/utils | |
| parent | 248d5dc99aad62bfeab45271d7b2ba0a78e8f6a6 (diff) | |
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.
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/helpers/format.ts | 12 |
1 files changed, 12 insertions, 0 deletions
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 } }; + }); +}; |
