layout.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import '../globals.css';
  2. import { visibleArticles } from '@/lib/blog/data';
  3. import Navbar from '@/components/Navbar';
  4. import Footer from '@/components/Footer';
  5. import { Toaster } from 'react-hot-toast';
  6. import { LanguageProvider } from '@/lib/i18n/LanguageContext';
  7. import RetroConfirmDialog from '@/components/common/RetroConfirmDialog';
  8. import { headers } from 'next/headers';
  9. import { requestLocale } from '@/lib/i18n/request';
  10. import { getMessages } from '@/lib/i18n/dictionaries';
  11. import { formattingLocale } from '@/lib/i18n/config';
  12. import { isAdminPath } from '@/lib/i18n/routes';
  13. export default function RootLayout({ children }: { children: React.ReactNode }) {
  14. const locale = requestLocale();
  15. const admin = isAdminPath(headers().get('x-strata-path') || '/');
  16. const messages = admin ? undefined : getMessages(locale);
  17. return (
  18. <html lang={formattingLocale(locale)}>
  19. <body className="bg-slate-50 min-h-screen flex flex-col font-sans">
  20. <LanguageProvider initialLang={locale} detectPreference={admin} navigateOnLanguageChange={!admin} messages={messages} localizedUI={!admin}>
  21. {!admin && <a href="#main-content" className="sr-only focus:not-sr-only focus:absolute focus:top-2 focus:left-2 focus:z-[100] focus:bg-amber-300 focus:border-2 focus:border-black focus:p-3">{messages?.['跳到主要内容']}</a>}
  22. <Navbar showBlog={visibleArticles('en').length > 0} />
  23. <main id="main-content" tabIndex={-1} className={admin ? 'flex-grow' : 'flex-grow min-w-0 [overflow-wrap:anywhere] hyphens-auto'}>
  24. {children}
  25. </main>
  26. <Footer />
  27. <RetroConfirmDialog />
  28. </LanguageProvider>
  29. <Toaster
  30. position="top-center"
  31. reverseOrder={false}
  32. toastOptions={{
  33. duration: 3500,
  34. className: '!border-2 !border-black !bg-neutral-50 !text-black !font-mono !text-xs !shadow-[4px_4px_0px_#000] !rounded-none !px-4 !py-3',
  35. success: {
  36. iconTheme: {
  37. primary: '#000',
  38. secondary: '#6ee7b7',
  39. },
  40. },
  41. error: {
  42. iconTheme: {
  43. primary: '#000',
  44. secondary: '#fecdd3',
  45. },
  46. },
  47. }}
  48. />
  49. </body>
  50. </html>
  51. );
  52. }