-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code: kept working on adoption of i18n
- Loading branch information
Showing
75 changed files
with
3,489 additions
and
2,510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { notFound } from 'next/navigation'; | ||
import type { FC } from 'react'; | ||
|
||
import getDynamicRouter from '@/next.dynamic.mjs'; | ||
import { | ||
availableLocaleCodes, | ||
availableLocales, | ||
defaultLocale, | ||
} from '@/next.locales.mjs'; | ||
import Theme from '@/theme'; | ||
|
||
type DynamicStaticPaths = { path: string[]; locale: string }; | ||
|
||
const dynamicRouter = await getDynamicRouter(); | ||
|
||
// This method is used to retrieve all native statically supported pages (SCR) that | ||
// we want to provide during build-time + allow fallback for dynamic pages during (ISR) | ||
export const generateStaticParams = async () => { | ||
const paths: DynamicStaticPaths[] = []; | ||
|
||
for (const locale of availableLocales) { | ||
const routesForLanguage = await dynamicRouter.getRoutesByLanguage( | ||
locale.code | ||
); | ||
|
||
const mappedRoutesWithLocale = routesForLanguage.map(pathname => | ||
dynamicRouter.mapPathToRoute(locale.code, pathname) | ||
); | ||
|
||
paths.push(...mappedRoutesWithLocale); | ||
} | ||
|
||
return paths.sort(); | ||
}; | ||
|
||
const DynamicPage: FC<{ params: DynamicStaticPaths }> = async ({ params }) => { | ||
const { path = [], locale = defaultLocale.code } = params; | ||
|
||
console.log(locale); | ||
|
||
if (!availableLocaleCodes.includes(locale)) { | ||
return notFound(); | ||
} | ||
|
||
const pathname = dynamicRouter.getPathname(path); | ||
|
||
if (dynamicRouter.shouldIgnoreRoute(pathname)) { | ||
return notFound(); | ||
} | ||
|
||
// Retrieves and rewriting rule if the pathname matches any rule | ||
const [, rewriteRule] = dynamicRouter.getRouteRewrite(pathname); | ||
|
||
// We retrieve the source of the Markdown file by doing an educated guess | ||
// of what possible files could be the source of the page, since the extension | ||
// context is lost from `getStaticProps` as a limitation of Next.js itself | ||
const { source, filename } = dynamicRouter.getMarkdownFile( | ||
locale, | ||
rewriteRule ? rewriteRule(pathname) : pathname | ||
); | ||
|
||
if (source.length && filename.length) { | ||
// This parses the actual Markdown content and returns a full set of props | ||
// to be passed to the base page (`DynamicPage`) which will render the Markdown | ||
const mdxProps = await dynamicRouter.getMDXProps(source, filename); | ||
|
||
// This retrieves the locale-specific props for the page, which are used | ||
// to render translations and locale data | ||
const localeProps = await dynamicRouter.getLocaleProps(locale); | ||
|
||
return <Theme {...mdxProps} {...localeProps} />; | ||
} | ||
|
||
return notFound(); | ||
}; | ||
|
||
export default DynamicPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Analytics } from '@vercel/analytics/react'; | ||
import { Source_Sans_3 } from 'next/font/google'; | ||
import { NextIntlClientProvider, useMessages } from 'next-intl'; | ||
import type { FC, PropsWithChildren } from 'react'; | ||
|
||
import { VERCEL_ENV } from '@/next.constants.mjs'; | ||
|
||
import '@/styles/old/index.css'; | ||
|
||
const sourceSans = Source_Sans_3({ | ||
weight: ['400', '600'], | ||
display: 'fallback', | ||
subsets: ['latin'], | ||
}); | ||
|
||
type LocaleLayout = PropsWithChildren<{ params: { locale: string } }>; | ||
|
||
const LocaleLayout: FC<LocaleLayout> = ({ children, params: { locale } }) => { | ||
const messages = useMessages(); | ||
|
||
return ( | ||
<html lang={locale} className={sourceSans.className}> | ||
<body> | ||
<NextIntlClientProvider locale={locale} messages={messages}> | ||
{children} | ||
</NextIntlClientProvider> | ||
|
||
{VERCEL_ENV && <Analytics />} | ||
|
||
<a rel="me" href="https://social.lfx.dev/@nodejs" /> | ||
</body> | ||
</html> | ||
); | ||
}; | ||
|
||
export default LocaleLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.