|
1 | | -/** |
2 | | - * This file extends on the `page.tsx` file, which is the default file that is used to render |
3 | | - * the entry points for each locale and then also reused within the [...path] route to render the |
4 | | - * and contains all logic for rendering our dynamic and static routes within the Node.js Website. |
5 | | - * |
6 | | - * Note: that each `page.tsx` should have its own `generateStaticParams` to prevent clash of |
7 | | - * dynamic params, which will lead on static export errors and other sort of issues. |
8 | | - */ |
9 | | - |
10 | | -import { availableLocaleCodes, defaultLocale } from '@node-core/website-i18n'; |
11 | | -import { notFound } from 'next/navigation'; |
12 | | - |
13 | | -import { ENABLE_STATIC_EXPORT } from '#site/next.constants.mjs'; |
14 | | -import { ENABLE_STATIC_EXPORT_LOCALE } from '#site/next.constants.mjs'; |
15 | | -import { dynamicRouter } from '#site/next.dynamic.mjs'; |
16 | | -import * as basePage from '#site/next.dynamic.page.mjs'; |
17 | | - |
18 | | -import type { DynamicParams } from '#site/types'; |
19 | | -import type { FC } from 'react'; |
20 | | - |
21 | | -type PageParams = DynamicParams<{ path: Array<string> }>; |
22 | | - |
23 | | -// This is the default Viewport Metadata |
24 | | -// @see https://nextjs.org/docs/app/api-reference/functions/generate-viewport#generateviewport-function |
25 | | -export const generateViewport = basePage.generateViewport; |
26 | | - |
27 | | -// This generates each page's HTML Metadata |
28 | | -// @see https://nextjs.org/docs/app/api-reference/functions/generate-metadata |
29 | | -export const generateMetadata = basePage.generateMetadata; |
30 | | - |
31 | | -// Generates all possible static paths based on the locales and environment configuration |
32 | | -// - Returns an empty array if static export is disabled (`ENABLE_STATIC_EXPORT` is false) |
33 | | -// - If `ENABLE_STATIC_EXPORT_LOCALE` is true, generates paths for all available locales |
34 | | -// - Otherwise, generates paths only for the default locale |
35 | | -// @see https://nextjs.org/docs/app/api-reference/functions/generate-static-params |
36 | | -export const generateStaticParams = async () => { |
37 | | - // Return an empty array if static export is disabled |
38 | | - if (!ENABLE_STATIC_EXPORT) { |
39 | | - return []; |
40 | | - } |
41 | | - |
42 | | - const routes = await dynamicRouter.getAllRoutes(); |
43 | | - |
44 | | - // Helper function to fetch and map routes for a specific locale |
45 | | - const getRoutesForLocale = async (l: string) => |
46 | | - routes.map(pathname => dynamicRouter.mapPathToRoute(l, pathname)); |
47 | | - |
48 | | - // Determine which locales to include in the static export |
49 | | - const locales = ENABLE_STATIC_EXPORT_LOCALE |
50 | | - ? availableLocaleCodes |
51 | | - : [defaultLocale.code]; |
52 | | - |
53 | | - // Generates all possible routes for all available locales |
54 | | - const routesWithLocales = await Promise.all(locales.map(getRoutesForLocale)); |
55 | | - |
56 | | - return routesWithLocales.flat().sort(); |
57 | | -}; |
58 | | - |
59 | | -// This method parses the current pathname and does any sort of modifications needed on the route |
60 | | -// then it proceeds to retrieve the Markdown file and parse the MDX Content into a React Component |
61 | | -// finally it returns (if the locale and route are valid) the React Component with the relevant context |
62 | | -// and attached context providers for rendering the current page |
63 | | -const getPage: FC<PageParams> = async props => { |
64 | | - const { path, locale: routeLocale } = await props.params; |
65 | | - |
66 | | - // Gets the current full pathname for a given path |
67 | | - const [locale, pathname] = basePage.getLocaleAndPath(path, routeLocale); |
68 | | - |
69 | | - // Gets the Markdown content and context |
70 | | - const [content, context] = await basePage.getMarkdownContext({ |
71 | | - locale, |
72 | | - pathname, |
73 | | - }); |
74 | | - |
75 | | - // If we have a filename and layout then we have a page |
76 | | - if (context.filename && context.frontmatter.layout) { |
77 | | - return basePage.renderPage({ |
78 | | - content, |
79 | | - layout: context.frontmatter.layout, |
80 | | - context, |
81 | | - }); |
82 | | - } |
83 | | - |
84 | | - return notFound(); |
85 | | -}; |
86 | | - |
87 | | -// Enforces that this route is used as static rendering |
88 | | -// Except whenever on the Development mode as we want instant-refresh when making changes |
89 | | -// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic |
90 | | -export const dynamic = 'force-static'; |
91 | | - |
92 | | -// Ensures that this endpoint is invalidated and re-executed every X minutes |
93 | | -// so that when new deployments happen, the data is refreshed |
94 | | -// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#revalidate |
95 | | -export const revalidate = 300; |
96 | | - |
97 | | -export default getPage; |
| 1 | +export * from '../page'; |
| 2 | +export { default } from '../page'; |
0 commit comments