Files
community-rule/app/layout.tsx
T
adilallo f7d88a7d5c Let Cloudron turn on named admins, the ops token, and Umami after the image is built.
Tracker env is read at request time and the CSP already allows the analytics host, so staging can set a rule admin, an ops bearer token, and the cookieless Umami site without rebuilding.
2026-11-23 11:51:55 -07:00

178 lines
4.8 KiB
TypeScript

import { Inter, Bricolage_Grotesque } from "next/font/google";
import type { Metadata, Viewport } from "next";
import { Suspense, type ReactNode } from "react";
import { headers } from "next/headers";
import { connection } from "next/server";
import Script from "next/script";
import messages from "../messages/en/index";
import { ASSETS, getAssetPath } from "../lib/assetUtils";
import {
defaultShareImages,
originFromHost,
resolveRequestHost,
} from "../lib/siteMetadata";
import { umamiTracker } from "../lib/umami";
import "./globals.css";
// Session chrome (`ConditionalNavigation`) lives in `(marketing)`, `(app)`, and
// `(admin)` layouts, behind `<Suspense>`, so the static shell can prerender while
// the header streams with the request cookie.
//
// MessagesProvider + AuthModalProvider are mounted per route group (Phase 4b):
// `(marketing)` gets a trimmed slice without `create.*` (~41 KB gzipped saved
// per static page); `(app)`/`(admin)`/`(dev)` get the full tree. See
// `messages/en/marketing.ts` and `docs/perf/next16-eval.md`.
const inter = Inter({
subsets: ["latin"],
weight: ["400", "500", "600", "700"],
style: ["normal", "italic"],
variable: "--font-inter",
display: "swap",
preload: true,
fallback: ["system-ui", "arial"],
});
const bricolageGrotesque = Bricolage_Grotesque({
subsets: ["latin"],
weight: "variable",
axes: ["opsz"],
variable: "--font-bricolage-grotesque",
display: "swap",
preload: true,
fallback: ["system-ui", "arial"],
});
const homeMeta = messages.metadata.home;
/** Viewport and favicon use the Metadata / Viewport APIs; avoid a manual `<head>` with a second viewport `meta` (duplicates Next's head injection). */
export const viewport: Viewport = {
width: "device-width",
initialScale: 1,
};
export async function generateMetadata(): Promise<Metadata> {
const headerStore = await headers();
const host = resolveRequestHost(
headerStore.get("x-forwarded-host"),
headerStore.get("host"),
);
return {
title: {
default: homeMeta.title,
template: messages.metadata.titleTemplate,
},
description: homeMeta.description,
keywords: [...homeMeta.keywords],
authors: [{ name: "Media Economies Design Lab" }],
creator: "Media Economies Design Lab",
publisher: "Media Economies Design Lab",
formatDetection: {
email: false,
address: false,
telephone: false,
},
metadataBase: new URL(originFromHost(host)),
icons: {
icon: [
{ url: getAssetPath(ASSETS.LOGO), type: "image/svg+xml" },
{ url: "/favicon.ico", sizes: "any" },
{
url: "/favicon-32x32.png",
sizes: "32x32",
type: "image/png",
},
{
url: "/favicon-16x16.png",
sizes: "16x16",
type: "image/png",
},
],
apple: [
{
url: "/apple-touch-icon.png",
sizes: "180x180",
type: "image/png",
},
],
},
openGraph: {
title: homeMeta.title,
description: homeMeta.description,
url: "/",
siteName: messages.metadata.siteName,
locale: "en_US",
type: "website",
images: defaultShareImages(),
},
twitter: {
card: "summary_large_image",
title: homeMeta.title,
description: homeMeta.description,
images: defaultShareImages().map((image) => image.url),
},
robots: {
index: true,
follow: true,
googleBot: {
index: true,
follow: true,
"max-video-preview": -1,
"max-image-preview": "large",
"max-snippet": -1,
},
},
};
}
async function UmamiScript() {
await connection();
const umami = umamiTracker();
if (!umami) return null;
return (
<Script
src={umami.src}
strategy="afterInteractive"
data-website-id={umami.websiteId}
data-do-not-track="true"
data-exclude-search="true"
/>
);
}
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en" className="font-sans">
<head>
<link
rel="preload"
as="image"
href={getAssetPath(ASSETS.AVATAR_1)}
type="image/png"
/>
<link
rel="preload"
as="image"
href={getAssetPath(ASSETS.AVATAR_2)}
type="image/png"
/>
<link
rel="preload"
as="image"
href={getAssetPath(ASSETS.AVATAR_3)}
type="image/png"
/>
</head>
<body className={`${inter.variable} ${bricolageGrotesque.variable}`}>
<Suspense fallback={null}>
<UmamiScript />
</Suspense>
<div className="mx-auto flex min-h-screen w-full max-w-[1920px] flex-col">
{children}
</div>
</body>
</html>
);
}