From b9069ab2d00337608c3a5c89184d28587ca4d470 Mon Sep 17 00:00:00 2001 From: 1aron Date: Tue, 30 Jan 2024 17:23:52 +0800 Subject: [PATCH] Update import paths in layout files --- website/app/[locale]/(root)/layout.tsx | 2 +- website/app/[locale]/examples/layout.tsx | 2 +- website/app/[locale]/play/layout.tsx | 2 +- website/app/{[locale] => }/client.tsx | 0 website/app/{[locale] => }/layout.tsx | 0 website/app/not-found.tsx | 29 ++++++++++++++++++++ website/app/{[locale] => }/root.layout.tsx | 32 ++++------------------ website/components/DocSidebar.tsx | 4 +-- website/i18n/tw.json | 2 ++ 9 files changed, 42 insertions(+), 31 deletions(-) rename website/app/{[locale] => }/client.tsx (100%) rename website/app/{[locale] => }/layout.tsx (100%) create mode 100644 website/app/not-found.tsx rename website/app/{[locale] => }/root.layout.tsx (51%) diff --git a/website/app/[locale]/(root)/layout.tsx b/website/app/[locale]/(root)/layout.tsx index b3a36c104..456c000ed 100644 --- a/website/app/[locale]/(root)/layout.tsx +++ b/website/app/[locale]/(root)/layout.tsx @@ -1,5 +1,5 @@ import { importTranslations } from '~/i18n' -import RootLayout from '../root.layout' +import RootLayout from '../../root.layout' import i18n from '~/i18n.config.mjs' export const metadata = { diff --git a/website/app/[locale]/examples/layout.tsx b/website/app/[locale]/examples/layout.tsx index db73d0b13..a244f5f50 100644 --- a/website/app/[locale]/examples/layout.tsx +++ b/website/app/[locale]/examples/layout.tsx @@ -1,5 +1,5 @@ import { importTranslations } from '~/i18n' -import RootLayout from '../root.layout' +import RootLayout from '../../root.layout' import i18n from '~/i18n.config.mjs' export const metadata = { diff --git a/website/app/[locale]/play/layout.tsx b/website/app/[locale]/play/layout.tsx index 451ec3992..5d48602b9 100644 --- a/website/app/[locale]/play/layout.tsx +++ b/website/app/[locale]/play/layout.tsx @@ -1,4 +1,4 @@ -import RootLayout from '../root.layout' +import RootLayout from '../../root.layout' import metadata from './metadata' import { generate } from '~/utils/metadata' import Script from 'next/script' diff --git a/website/app/[locale]/client.tsx b/website/app/client.tsx similarity index 100% rename from website/app/[locale]/client.tsx rename to website/app/client.tsx diff --git a/website/app/[locale]/layout.tsx b/website/app/layout.tsx similarity index 100% rename from website/app/[locale]/layout.tsx rename to website/app/layout.tsx diff --git a/website/app/not-found.tsx b/website/app/not-found.tsx new file mode 100644 index 000000000..feaa18eb2 --- /dev/null +++ b/website/app/not-found.tsx @@ -0,0 +1,29 @@ +import { importTranslations } from '~/i18n' +import RootLayout from './root.layout' +import i18n from '~/i18n.config.mjs' +import SearchButton from 'websites/components/SearchButton' +import DocHeader from '~/components/DocHeader' +import { createTranslation } from '~/i18n' +import { headers } from 'next/headers' + +export default async function NotFound() { + const headersList = headers() + const domain = headersList.get('x-forwarded-proto') + '://' + headersList.get('host') + const referer = headersList.get('referer') + let locale = referer?.replace(domain, '')?.split('/')?.[1] + locale = i18n.locales.find((eachLocale) => eachLocale === locale) || 'en' + const $ = await createTranslation(locale) + return ( + + +
+

404

+

{$('This page does not exist')}

+
+

{$('Sorry, the page cannot be found. Please try searching for other content.')}

+ +
+
+
+ ) +} diff --git a/website/app/[locale]/root.layout.tsx b/website/app/root.layout.tsx similarity index 51% rename from website/app/[locale]/root.layout.tsx rename to website/app/root.layout.tsx index f22368cd8..ec9674608 100644 --- a/website/app/[locale]/root.layout.tsx +++ b/website/app/root.layout.tsx @@ -1,24 +1,14 @@ 'use client' -import '../globals.css' +import './globals.css' import { getPreInitScript } from 'theme-service' import clsx from 'clsx' import { HTMLAttributes } from 'react' -import { importTranslations } from '~/i18n' - -import { RedirectsProvider } from 'websites/contexts/redirects' -import { LocaleProvider } from 'websites/contexts/locale' -import { I18nProvider } from 'websites/contexts/i18n' -import redirects from '~/redirects.mjs' -import { Analytics } from '@vercel/analytics/react' -import config from '~/master.css' -import CSSRuntimeProvider from '@master/css.react/CSSRuntimeProvider' -import ThemeServiceProvider from '@master/css.react/ThemeServiceProvider' -import { SpeedInsights } from '@vercel/speed-insights/next' import i18n from '~/i18n.config.mjs' +import Client from './client' export default function RootLayout({ children, locale, bodyClassName, style, translations }: { - children: JSX.Element, + children: JSX.Element[] | JSX.Element, locale: typeof i18n['locales'][number], style?: HTMLAttributes['style'], bodyClassName?: string, @@ -33,19 +23,9 @@ export default function RootLayout({ children, locale, bodyClassName, style, tra {locale === 'tw' && } - - - - - - {children} - - - - - - - + + {children} + ) diff --git a/website/components/DocSidebar.tsx b/website/components/DocSidebar.tsx index 1fbec90fa..73f0f4576 100644 --- a/website/components/DocSidebar.tsx +++ b/website/components/DocSidebar.tsx @@ -10,10 +10,10 @@ export default function DocSidebar() { const $ = useTranslation() return ( // eslint-disable-next-line @master/css/class-validation -