initial commit
This commit is contained in:
76
app/layout.tsx
Normal file
76
app/layout.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
import type { Metadata } from "next";
|
||||
import { headers } from "next/headers";
|
||||
import type { ReactNode } from "react";
|
||||
import de from "@/locales/de.json";
|
||||
import en from "@/locales/en.json";
|
||||
import es from "@/locales/es.json";
|
||||
import fr from "@/locales/fr.json";
|
||||
import it from "@/locales/it.json";
|
||||
import sv from "@/locales/sv.json";
|
||||
import "./globals.css";
|
||||
|
||||
type Locale = "en" | "es" | "fr" | "de" | "it" | "sv";
|
||||
|
||||
const descriptions: Record<Locale, string> = {
|
||||
en: en.hero.lede,
|
||||
es: es.hero.lede,
|
||||
fr: fr.hero.lede,
|
||||
de: de.hero.lede,
|
||||
it: it.hero.lede,
|
||||
sv: sv.hero.lede,
|
||||
};
|
||||
|
||||
async function pickLocaleFromHeaders(): Promise<Locale> {
|
||||
const hdrs = await headers();
|
||||
const accept = hdrs.get("accept-language") || "";
|
||||
const entries = accept.split(",").map((entry) => entry.trim().toLowerCase());
|
||||
const match = entries.find((entry) =>
|
||||
["es", "fr", "de", "it", "sv", "en"].some((code) => entry.startsWith(code))
|
||||
);
|
||||
if (!match) return "en";
|
||||
if (match.startsWith("es")) return "es";
|
||||
if (match.startsWith("fr")) return "fr";
|
||||
if (match.startsWith("de")) return "de";
|
||||
if (match.startsWith("it")) return "it";
|
||||
if (match.startsWith("sv")) return "sv";
|
||||
return "en";
|
||||
}
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const locale = await pickLocaleFromHeaders();
|
||||
return {
|
||||
title: "PolyNote",
|
||||
description: descriptions[locale] ?? descriptions.en,
|
||||
metadataBase: new URL("https://polynote.wittrail.com"),
|
||||
openGraph: {
|
||||
title: "PolyNote",
|
||||
description: descriptions[locale] ?? descriptions.en,
|
||||
url: "https://polynote.wittrail.com",
|
||||
siteName: "PolyNote",
|
||||
images: [
|
||||
{
|
||||
url: "/logo.svg",
|
||||
width: 256,
|
||||
height: 256,
|
||||
alt: "PolyNote logo",
|
||||
},
|
||||
],
|
||||
locale,
|
||||
type: "website",
|
||||
},
|
||||
icons: {
|
||||
icon: "/favicon.ico",
|
||||
shortcut: "/favicon.ico",
|
||||
apple: "/favicon.png",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default async function RootLayout({ children }: { children: ReactNode }) {
|
||||
const locale = await pickLocaleFromHeaders();
|
||||
return (
|
||||
<html lang={locale}>
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user