@@ -11,13 +11,35 @@ import { notFound } from 'next/navigation';
1111import type { FC } from 'react' ;
1212
1313import * as basePage from '#site/app/[locale]/page' ;
14+ import { provideBlogPosts } from '#site/next-data/providers/blogData' ;
1415import { ENABLE_STATIC_EXPORT } from '#site/next.constants.mjs' ;
15- import { BLOG_DYNAMIC_ROUTES } from '#site/next.dynamic.constants .mjs' ;
16+ import { blogData } from '#site/next.json .mjs' ;
1617import { defaultLocale } from '#site/next.locales.mjs' ;
1718
1819type DynamicStaticPaths = { path : Array < string > ; locale : string } ;
1920type DynamicParams = { params : Promise < DynamicStaticPaths > } ;
2021
22+ /**
23+ * This constant is used to create static routes on-the-fly that do not have a file-system
24+ * counterpart route. This is useful for providing routes with matching Layout Names
25+ * but that do not have Markdown content and a matching file for the route
26+ *
27+ * @type {Array<string> } A Map of pathname and Layout Name
28+ */
29+ export const BLOG_DYNAMIC_ROUTES = [
30+ // Provides Routes for all Blog Categories
31+ ...blogData . categories ,
32+ // Provides Routes for all Blog Categories w/ Pagination
33+ ...blogData . categories
34+ // retrieves the amount of pages for each blog category
35+ . map ( c => [ c , provideBlogPosts ( c ) . pagination . pages ] )
36+ // creates a numeric array for each page and define a pathname for
37+ // each page for a category (i.e. blog/all/page/1)
38+ . map ( ( [ c , t ] ) => [ ...Array ( t ) . keys ( ) ] . map ( p => `${ c } /page/${ p + 1 } ` ) )
39+ // flattens the array since we have a .map inside another .map
40+ . flat ( ) ,
41+ ] ;
42+
2143// This is the default Viewport Metadata
2244// @see https://nextjs.org/docs/app/api-reference/functions/generate-viewport#generateviewport-function
2345export const generateViewport = basePage . generateViewport ;
0 commit comments