---
import { getUICopy } from "@/lib/ui-copy";
const ui = getUICopy(Astro.url.pathname);
import "@fontsource-variable/inter";
import "@fontsource-variable/jetbrains-mono";
import "../styles/globals.css";
import "../styles/prose.css";
import { config } from "virtual:nimbus/config";
import { getCollectionLlmsUrl, getVersionStatus } from "@cloudflare/nimbus-docs";
import AgentDirective from "@/components/AgentDirective.astro";
import { hasLocaleTwin, warmLocaleIndex } from "@/components/site-nav/locale-links";
import { existingAlternates, localizedPaths } from "@/lib/alternates";
import { SearchDialog } from "@/components/ui/search";
import SEOHead from "@/components/SEOHead.astro";
import LanguagePreference from "@/components/LanguagePreference.astro";
import type { BasePageProps } from "@cloudflare/nimbus-docs/types";
type Props = BasePageProps & { lang?: string; localized?: boolean };
const {
title,
description,
noindex,
markdownUrl,
socialImage,
lastUpdated,
head: pageHead = [],
collection,
entryId,
lang,
localized = false,
} = Astro.props;
// Per-page `lang` prop wins (locale routes pass it); falls back to the
// configured site locale, then `en`.
const resolvedLang = lang ?? config.locale ?? "en";
// hreflang alternates for the languages that really serve this page — an
// alternate pointing at a redirect stub is worse than none. Content-backed
// pages (docs: they carry an `entryId`) resolve through the shared twin index
// the navbar/LanguageSwitcher/sidebar already use, so the cluster shrinks to
// the languages holding the same entry; landing pages and the /evidence
// archive are mirrored into all 15 languages and keep the full set without
// loading the index. English is the `x-default` target and is only emitted
// (with `x-default`) when its twin exists.
let altLinks = localized
? localizedPaths(Astro.url.pathname, resolvedLang)
: null;
if (altLinks && entryId) {
await warmLocaleIndex();
altLinks = existingAlternates(altLinks, (altLang) =>
hasLocaleTwin(entryId, altLang),
);
}
const defaultAlt = altLinks?.find(({ lang: altLang }) => altLang === "en");
const altHref = (path: string) =>
Astro.site ? new URL(path, Astro.site).href : path;
// SEOHead emits self-canonicals and page-specific language metadata. Translated
// collections must not be treated as older versions of the English documents.
// Per-page agent-index pointer. For pages in non-primary or version
// collections, this resolves to `/<prefix>/llms.txt` (e.g. `/v0/llms.txt`
// for a v0 docs page, `/blog/llms.txt` for a blog post). Falls back to
// the root `/llms.txt` when no collection is provided.
// Hidden-version pages don't advertise an agent index (the per-version
// llms.txt isn't emitted for them); suppress the AgentDirective entirely.
const versionStatus = collection ? await getVersionStatus(collection) : null;
const isHiddenVersion = versionStatus?.isHidden === true;
const llmsIndexPath = collection
? await getCollectionLlmsUrl(collection)
: "/llms.txt";
const llmsUrl = Astro.site
? new URL(llmsIndexPath, Astro.site).href
: llmsIndexPath;
---
<!doctype html>
<html lang={resolvedLang} dir={resolvedLang === "ar" ? "rtl" : "ltr"} style="color-scheme: light">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<LanguagePreference />
<script is:inline>
(() => {
const KEY = "ui-mode";
const readPref = () => {
try {
const v = localStorage.getItem(KEY);
return v === "dark" || v === "light" ? v : null;
} catch {
return null;
}
};
// Start in the site's light palette; an explicit visitor choice wins.
const resolveMode = () => readPref() ?? "light";
const applyTheme = () => {
const root = document.documentElement;
const mode = resolveMode();
if (mode === "dark") root.setAttribute("data-mode", "dark");
else root.removeAttribute("data-mode");
root.style.colorScheme = mode;
document.querySelectorAll("[data-nb-theme-toggle]").forEach((b) => {
b.setAttribute("data-nb-state", mode);
});
};
applyTheme();
window.addEventListener("storage", (e) => {
if (e.key === KEY) applyTheme();
});
window.__nbApplyTheme = applyTheme;
})();
</script>
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link
rel="icon"
type="image/svg+xml"
href="/favicon-dark.svg"
media="(prefers-color-scheme: dark)"
/>
<SEOHead
title={title}
description={description}
noindex={noindex || isHiddenVersion}
markdownUrl={isHiddenVersion ? undefined : markdownUrl}
socialImage={socialImage}
lastUpdated={lastUpdated}
head={pageHead}
lang={resolvedLang}
llmsUrl={isHiddenVersion ? undefined : llmsUrl}
/>
{altLinks?.map(({ lang: altLang, path }) => (
<link rel="alternate" hreflang={altLang} href={altHref(path)} />
))}
{defaultAlt && (
<link
rel="alternate"
hreflang="x-default"
href={altHref(defaultAlt.path)}
/>
)}
</head>
<body class="min-h-screen bg-background text-foreground antialiased">
<a
href="#main-content"
class="sr-only focus:not-sr-only focus:absolute focus:left-2 focus:top-2 focus:z-100 focus:rounded-md focus:bg-primary focus:px-4 focus:py-2 focus:text-sm focus:font-medium focus:text-primary-foreground focus:no-underline focus-visible:outline-2 focus-visible:outline-ring focus-visible:outline-offset-2"
>
{ui.skip}
</a>
{markdownUrl && !isHiddenVersion && <AgentDirective markdownUrl={markdownUrl} llmsUrl={llmsUrl} />}
<slot />
{config.search !== false && <SearchDialog />}
<script>
import "@/scripts/docs-copy";
</script>
</body>
</html>