Layout.tsx 1.7 KB

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