From 5b6639a3cf9b6c63045cb82e6ef1a43b0742c367 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Wed, 9 Mar 2022 00:38:02 +0100 Subject: feat: provide pagination for users with js disabled (#13) * chore: add a Pagination component * chore: add blog pages * chore: fallback to page number based navigation if JS disabled * chore: update translation --- src/utils/helpers/format.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/utils') diff --git a/src/utils/helpers/format.ts b/src/utils/helpers/format.ts index 9c6f266..71455b6 100644 --- a/src/utils/helpers/format.ts +++ b/src/utils/helpers/format.ts @@ -1,4 +1,4 @@ -import { ParamsSlug, Slug } from '@ts/types/app'; +import { ParamsIds, ParamsSlug, Slug } from '@ts/types/app'; import { Article, ArticlePreview, @@ -293,3 +293,18 @@ export const getFormattedPaths = (array: Slug[]): ParamsSlug[] => { return { params: { slug: object.slug } }; }); }; + +/** + * Convert a number of pages to an array of params with ids. + * @param {number} totalPages - The total pages. + * @returns {ParamsIds} An array of params with ids. + */ +export const getFormattedPageNumbers = (totalPages: number): ParamsIds[] => { + const paths = []; + + for (let i = 1; i <= totalPages; i++) { + paths.push({ params: { id: `${i}` } }); + } + + return paths; +}; -- cgit v1.2.3