import type { ComponentProps, JSX } from "solid-js" import { NoHydration, ssr } from "solid-js/web" import { CodeFrame } from "~/component/site/code-frame" import type { Locale } from "~/lib/language" import { FileTree } from "~/component/site/file-type-icon" import { HeadingLink } from "~/component/site/on-this-page" import { useI18n } from "~/context/i18n" import { I18nContext } from "~/context/i18n-context" import { dict } from "~/i18n/en" import { Callout } from "./components/Callout" import { Card } from "./components/Card" import { CardGroup } from "./components/CardGroup" import { CodeBlock } from "./components/CodeBlock" import { CodeTabs } from "./components/CodeTabs" import { OpenApiReference } from "./components/OpenApiReference" import { PlanTabs } from "./components/PlanTabs" import { Slot } from "./components/Slot" import { Tabs } from "./components/Tabs" import type { DocsSet } from "./config" import { docsFiles, docsTranslationFiles, type DocsModule } from "./content" import { DocsLayout, type DocsAssets, type DocsV1, type DocsVersions } from "./layouts/DocsLayout" import { docsLocaleMarkdownHref, docsMarkdownHref, type DocsSection } from "./lib/navigation" import type { V1Locale } from "./lib/v1-navigation" /** * A docs page to render: a set's content page and its module, or the API reference (no module), with * the page in each docs version and, on the V1 docs, its language's section and languages. */ export type DocsRender = { set: DocsSet slug: string module?: DocsModule assets: DocsAssets /** The latest docs' page language, and whether its content is translated (a fallback page shows English). */ locale: Locale translated: boolean /** The page (or its English source) says noindex: no robots, no hreflang, no sitemap. */ noindex: boolean /** The page's head languages: English and each current translation, itself included (render.tsx). */ alternates: readonly Locale[] /** The current section in the page's language, with its pages' titles (render.tsx). */ section: DocsSection versions?: DocsVersions v1?: DocsV1 } // rehype-shiki.ts leaves the labels of terminals, file trees and diffs to the page's language. function DocsCodeFrame(props: ComponentProps) { const i18n = useI18n() const label = props.kind === "terminal" ? "docs.code.terminal" : props.kind === "tree" ? "docs.code.files" : props.variant === "codeDiff" ? "docs.code.diff" : undefined return } // CodeFrame, FileTree and HeadingLink are what rehype-shiki.ts and rehype-headings.ts put in the tree. const components = { Callout, Card, CardGroup, CodeBlock, CodeFrame: DocsCodeFrame, CodeTabs, FileTree, HeadingLink, PlanTabs, Slot, Tabs, } // The site's components and the docs' own read their copy from the I18n context: the page's // language's strings (the latest docs' site languages; the V1 docs have the site's languages and // Bosnian, src/i18n/bs.ts) with their {{params}} filled in (as ~/i18n's interpolate), without the // site's language loader. const dicts = import.meta.glob("../i18n/{ar,br,bs,da,de,es,fr,it,ja,ko,no,pl,ru,th,tr,uk,zh,zht}.ts", { eager: true, import: "dict", }) export const docsI18n = (locale?: Locale | V1Locale) => { const path = typeof locale === "string" ? locale : (locale?.site ?? locale?.path) const table = dicts[`../i18n/${path}.ts`] ?? dict return { t: (key: keyof typeof dict, params?: Record) => table[key].replace(/\{\{(\w+)\}\}/g, (raw, name: string) => String(params?.[name] ?? raw)), translated: () => true, } } // A Markdown link on a V1 page, with its anchor where it is on the page it goes to. const link = (anchor: (href: string) => string) => (props: JSX.AnchorHTMLAttributes) => ( ) /** * A whole docs page in the site's shell: plain HTML with the docs' own stylesheet and script, and no * hydration (NoHydration), so it ships no framework code. The site's components render here on the * server only; client.ts drives what they do in the browser. */ export function DocsDocument(props: DocsRender) { const module = props.module const source = props.set.id === "latest" && props.translated && props.locale !== "en" ? docsTranslationFiles.get(props.locale)?.get(props.slug) : docsFiles.get(props.set.id)?.get(props.slug) return ( {ssr("") as unknown as Element} {module ? ( ) : ( )} ) }