diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-03-09 00:38:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-09 00:38:02 +0100 |
| commit | 5b6639a3cf9b6c63045cb82e6ef1a43b0742c367 (patch) | |
| tree | 4e7cebf9f6b094d405e96febe743fea514cfca9f /src/utils | |
| parent | b0d9d8cb1c8c4a4d2b9234bbfdc7195fb563b21a (diff) | |
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
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/helpers/format.ts | 17 |
1 files changed, 16 insertions, 1 deletions
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; +}; |
