Layout.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import Head from "next/head"
  2. import { StaticImageData } from "next/image"
  3. import { useRouter } from "next/router"
  4. import Footer from "./Footer"
  5. import Header from "./Header"
  6. import { locales, defaultLocale } from "../data/locales"
  7. import defaultPreviewImage from "../public/preview.png"
  8. const BASE_URL = "https://joinmastodon.org"
  9. /** Default layout component */
  10. export const Layout = ({
  11. children,
  12. transparentHeader,
  13. previewImage,
  14. }: {
  15. children: React.ReactNode
  16. transparentHeader?: boolean
  17. previewImage?: StaticImageData
  18. }) => {
  19. const router = useRouter()
  20. const currentLocale = router.locale
  21. const currentPath = router.asPath
  22. const metaPreviewImage = previewImage || defaultPreviewImage;
  23. return (
  24. <div className="mx-auto max-w-site px-6 lg:px-16">
  25. <a
  26. className="sr-only top-0 left-0 z-20 block bg-blurple-900 text-white focus:not-sr-only focus:absolute focus:p-2"
  27. href="#main"
  28. >
  29. Skip to main content
  30. </a>
  31. <Header transparent={transparentHeader} />
  32. <main id="main">{children}</main>
  33. <Footer />
  34. <Head>
  35. <meta property="og:image" content={`${BASE_URL}${metaPreviewImage.src}`} />
  36. <meta property="twitter:card" content="summary_large_image" />
  37. {locales
  38. .filter((locale) => locale.code !== currentLocale)
  39. .map((locale) => (
  40. <link
  41. key={locale.code}
  42. rel="alternate"
  43. hrefLang={locale.code}
  44. href={`${BASE_URL}${
  45. locale.code === defaultLocale ? "" : `/${locale.code}`
  46. }${currentPath}`}
  47. />
  48. ))}
  49. <link
  50. rel="canonical"
  51. href={`${BASE_URL}${
  52. currentLocale === defaultLocale ? "" : `/${currentLocale}`
  53. }${currentPath}`}
  54. />
  55. </Head>
  56. </div>
  57. )
  58. }
  59. export default Layout