@@ -2,35 +2,37 @@ import { cache } from 'react';
22
33import generateBlogData from '@/next-data/generators/blogData.mjs' ;
44import { BLOG_POSTS_PER_PAGE } from '@/next.constants.mjs' ;
5- import type { BlogPostsRSC } from '@/types' ;
5+ import type { BlogCategory , BlogPostsRSC } from '@/types' ;
66
77const { categories, posts } = await generateBlogData ( ) ;
88
99export const provideBlogCategories = cache ( ( ) => categories ) ;
1010
11- export const provideBlogPosts = cache ( ( category : string ) : BlogPostsRSC => {
12- const categoryPosts = posts
13- . filter ( post => post . categories . includes ( category ) )
14- . sort ( ( a , b ) => b . date . getTime ( ) - a . date . getTime ( ) ) ;
11+ export const provideBlogPosts = cache (
12+ ( category : BlogCategory ) : BlogPostsRSC => {
13+ const categoryPosts = posts
14+ . filter ( post => post . categories . includes ( category ) )
15+ . sort ( ( a , b ) => b . date . getTime ( ) - a . date . getTime ( ) ) ;
1516
16- // Total amount of possible pages given the amount of blog posts
17- const total = categoryPosts . length / BLOG_POSTS_PER_PAGE ;
17+ // Total amount of possible pages given the amount of blog posts
18+ const total = categoryPosts . length / BLOG_POSTS_PER_PAGE ;
1819
19- return {
20- posts : categoryPosts ,
21- pagination : {
22- prev : null ,
23- next : null ,
24- // In case the division results on a remainder we need
25- // to have an extra page containing the remainder entries
26- pages : Math . floor ( total % 1 === 0 ? total : total + 1 ) ,
27- total : categoryPosts . length ,
28- } ,
29- } ;
30- } ) ;
20+ return {
21+ posts : categoryPosts ,
22+ pagination : {
23+ prev : null ,
24+ next : null ,
25+ // In case the division results on a remainder we need
26+ // to have an extra page containing the remainder entries
27+ pages : Math . floor ( total % 1 === 0 ? total : total + 1 ) ,
28+ total : categoryPosts . length ,
29+ } ,
30+ } ;
31+ }
32+ ) ;
3133
3234export const providePaginatedBlogPosts = cache (
33- ( category : string , page : number ) : BlogPostsRSC => {
35+ ( category : BlogCategory , page : number ) : BlogPostsRSC => {
3436 const { posts, pagination } = provideBlogPosts ( category ) ;
3537
3638 // This autocorrects if invalid numbers are given to only allow
0 commit comments