Skip to content

Commit 3b1fc58

Browse files
fixup! make site work with the Cloudflare OpenNext adapter
1 parent c2a8561 commit 3b1fc58

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

apps/site/app/[locale]/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const getPage: FC<DynamicParams> = async props => {
9292
// Gets the current full pathname for a given path
9393
const pathname = dynamicRouter.getPathname(path);
9494

95-
const staticGeneratedLayout = (await DYNAMIC_ROUTES()).get(pathname);
95+
const staticGeneratedLayout = DYNAMIC_ROUTES.get(pathname);
9696

9797
// If the current pathname is a statically generated route
9898
// it means it does not have a Markdown file nor exists under the filesystem

apps/site/next.dynamic.constants.mjs

+16-24
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,23 @@ export const IGNORED_ROUTES = [
2727
* counterpart route. This is useful for providing routes with matching Layout Names
2828
* but that do not have Markdown content and a matching file for the route
2929
*
30-
* @type {() => Promise<Map<string, import('./types').Layouts>>} A Map of pathname and Layout Name
30+
* @type {Map<string, import('./types').Layouts>} A Map of pathname and Layout Name
3131
*/
32-
export const DYNAMIC_ROUTES = async () => {
33-
const blogCategories = provideBlogCategories();
34-
35-
const pages = [];
36-
for (const c of blogCategories) {
37-
const categoryPages = (await provideBlogPosts(c)).pagination.pages;
38-
pages.push([c, categoryPages]);
39-
}
40-
41-
return new Map([
42-
// Provides Routes for all Blog Categories
43-
...blogCategories.map(c => [`blog/${c}`, 'blog-category']),
44-
// Provides Routes for all Blog Categories w/ Pagination
45-
...pages
46-
// creates a numeric array for each page and define a pathname for
47-
// each page for a category (i.e. blog/all/page/1)
48-
.map(([c, t]) => [...Array(t).keys()].map(p => `blog/${c}/page/${p + 1}`))
49-
// creates a tuple of each pathname and layout for the route
50-
.map(paths => paths.map(path => [path, 'blog-category']))
51-
// flattens the array since we have a .map inside another .map
52-
.flat(),
53-
]);
54-
};
32+
export const DYNAMIC_ROUTES = new Map([
33+
// Provides Routes for all Blog Categories
34+
...provideBlogCategories().map(c => [`blog/${c}`, 'blog-category']),
35+
// Provides Routes for all Blog Categories w/ Pagination
36+
...provideBlogCategories()
37+
// retrieves the amount of pages for each blog category
38+
.map(c => [c, provideBlogPosts(c).pagination.pages])
39+
// creates a numeric array for each page and define a pathname for
40+
// each page for a category (i.e. blog/all/page/1)
41+
.map(([c, t]) => [...Array(t).keys()].map(p => `blog/${c}/page/${p + 1}`))
42+
// creates a tuple of each pathname and layout for the route
43+
.map(paths => paths.map(path => [path, 'blog-category']))
44+
// flattens the array since we have a .map inside another .map
45+
.flat(),
46+
]);
5547

5648
/**
5749
* This is the default Next.js Page Metadata for all pages

apps/site/next.dynamic.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const getDynamicRouter = async () => {
9393

9494
return [...pathnameToFilename.keys()]
9595
.filter(shouldIgnoreStaticRoute)
96-
.concat([...(await DYNAMIC_ROUTES()).keys()]);
96+
.concat([...DYNAMIC_ROUTES.keys()]);
9797
};
9898

9999
/**

0 commit comments

Comments
 (0)