1
1
import {
2
- provideBlogCategories ,
3
2
provideBlogPosts ,
4
3
providePaginatedBlogPosts ,
5
4
} from '@/next-data/providers/blogData' ;
6
- import { VERCEL_REVALIDATE } from '@/next.constants.mjs' ;
7
5
import { defaultLocale } from '@/next.locales.mjs' ;
8
6
9
7
type StaticParams = {
10
- params : { locale : string ; category : string ; page : string } ;
8
+ params : Promise < { locale : string ; category : string ; page : string } > ;
11
9
} ;
12
10
13
11
// This is the Route Handler for the `GET` method which handles the request
14
12
// for providing Blog Posts for Blog Categories and Pagination Metadata
15
13
// @see https://nextjs.org/docs/app/building-your-application/routing/router-handlers
16
- export const GET = async ( _ : Request , { params } : StaticParams ) => {
14
+ export const GET = async ( _ : Request , props : StaticParams ) => {
15
+ const params = await props . params ;
16
+
17
17
const requestedPage = Number ( params . page ) ;
18
18
19
19
const data =
@@ -27,41 +27,18 @@ export const GET = async (_: Request, { params }: StaticParams) => {
27
27
} ;
28
28
29
29
// This function generates the static paths that come from the dynamic segments
30
- // `[locale]/next-data/blog-data/[category]` and returns an array of all available static paths
31
- // This is used for ISR static validation and generation
32
- export const generateStaticParams = async ( ) => {
33
- // This metadata is the original list of all available categories and all available years
34
- // within the Node.js Website Blog Posts (2011, 2012...)
35
- const categories = provideBlogCategories ( ) ;
36
-
37
- const mappedCategories = categories . map ( category => {
38
- // gets the current pagination meta for a given category
39
- const { pagination } = provideBlogPosts ( category ) ;
40
-
41
- // creates a sequential array containing each page number
42
- const pages = [ ...Array ( pagination . pages ) . keys ( ) ] . map ( ( _ , key ) => key + 1 ) ;
43
-
44
- // maps the data into valid Next.js Route Engine routes with all required params
45
- // notice that we add an extra 0 in the beginning in case we want a non-paginated route
46
- return [ 0 , ...pages ] . map ( page => ( {
47
- locale : defaultLocale . code ,
48
- page : String ( page ) ,
49
- category,
50
- } ) ) ;
51
- } ) ;
52
-
53
- return mappedCategories . flat ( ) ;
54
- } ;
55
-
56
- // Enforces that only the paths from `generateStaticParams` are allowed, giving 404 on the contrary
57
- // @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams
58
- export const dynamicParams = false ;
30
+ // `[locale]/next-data/blog-data/[category]/[page]` this will return a default value as we don't want to
31
+ // statically generate this route as it is compute-expensive.
32
+ // Hence we generate a "fake" OG image during build just to satisfy Next.js requirements.
33
+ export const generateStaticParams = async ( ) => [
34
+ { locale : defaultLocale . code , category : 'all' , page : '0' } ,
35
+ ] ;
59
36
60
37
// Enforces that this route is cached and static as much as possible
61
38
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic
62
- export const dynamic = 'error ' ;
39
+ export const dynamic = 'force-static ' ;
63
40
64
41
// Ensures that this endpoint is invalidated and re-executed every X minutes
65
42
// so that when new deployments happen, the data is refreshed
66
43
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#revalidate
67
- export const revalidate = VERCEL_REVALIDATE ;
44
+ export const revalidate = 300 ;
0 commit comments