|
1 | | -import { notFound } from 'next/navigation'; |
| 1 | +import { notFound, redirect } from 'next/navigation'; |
2 | 2 | import type { FC } from 'react'; |
3 | 3 |
|
| 4 | +import provideReleaseData from '#site/next-data/providers/releaseData'; |
4 | 5 | import { ENABLE_STATIC_EXPORT } from '#site/next.constants.mjs'; |
5 | 6 | import { ARCHIVE_DYNAMIC_ROUTES } from '#site/next.dynamic.constants.mjs'; |
6 | 7 | import * as basePage from '#site/next.dynamic.page.mjs'; |
7 | 8 | import { defaultLocale } from '#site/next.locales.mjs'; |
| 9 | +import type { DynamicParams } from '#site/types'; |
8 | 10 |
|
9 | | -type DynamicStaticPaths = { version: string; locale: string }; |
10 | | -type DynamicParams = { params: Promise<DynamicStaticPaths> }; |
| 11 | +type PageParams = DynamicParams<{ version: string }>; |
11 | 12 |
|
12 | 13 | // This is the default Viewport Metadata |
13 | 14 | // @see https://nextjs.org/docs/app/api-reference/functions/generate-viewport#generateviewport-function |
@@ -38,12 +39,20 @@ export const generateStaticParams = async () => { |
38 | 39 | // then it proceeds to retrieve the Markdown file and parse the MDX Content into a React Component |
39 | 40 | // finally it returns (if the locale and route are valid) the React Component with the relevant context |
40 | 41 | // and attached context providers for rendering the current page |
41 | | -const getPage: FC<DynamicParams> = async props => { |
| 42 | +const getPage: FC<PageParams> = async props => { |
42 | 43 | const { version, locale: routeLocale } = await props.params; |
43 | 44 |
|
44 | 45 | // Gets the current full pathname for a given path |
45 | 46 | const [locale, pathname] = basePage.getLocaleAndPath(version, routeLocale); |
46 | 47 |
|
| 48 | + if (version === 'current') { |
| 49 | + const releaseData = provideReleaseData(); |
| 50 | + |
| 51 | + const release = releaseData.find(release => release.status === 'Current'); |
| 52 | + |
| 53 | + redirect(`/${locale}/download/archive/${release?.versionWithPrefix}`); |
| 54 | + } |
| 55 | + |
47 | 56 | // Verifies if the current route is a dynamic route |
48 | 57 | const isDynamicRoute = ARCHIVE_DYNAMIC_ROUTES.some(r => r.includes(pathname)); |
49 | 58 |
|
|
0 commit comments