Files
simple-react-app-kit/docs/src/entry-server.tsx
T

69 lines
2.0 KiB
TypeScript

import { StrictMode } from "react"
import { prerender } from "react-dom/static"
import App from "./App"
import {
getStaticDocRoutes,
resolveDocLocale,
resolveDocLocation,
} from "./content/registry"
import { getDocSearchIndex } from "./content/search-index.source"
import type { DocLocale } from "./content/types"
import { createDefaultDocsPreferences } from "./lib/preferences"
export { getStaticDocRoutes, getDocSearchIndex as getStaticSearchIndex }
export async function renderStaticPage(pathname: string) {
const locale = resolveDocLocale(pathname)
const { prelude } = await prerender(
<StrictMode>
<App
initialPreferences={createDefaultDocsPreferences(locale)}
initialUrl={new URL(pathname, "https://docs.local").href}
/>
</StrictMode>
)
return {
html: await new Response(prelude).text(),
locale,
metadata: getPageMetadata(pathname, locale),
}
}
function getPageMetadata(pathname: string, locale: DocLocale) {
const location = resolveDocLocation(pathname)
if (location) {
return {
description: location.page.description,
title: `${location.page.title} · ${location.package.label}`,
}
}
const english = locale === "en-US"
if (/\/settings\/?$/.test(pathname)) {
return {
description: english
? "Configure the documentation theme, colors, and language."
: "配置文档站的主题、颜色和语言。",
title: english ? "Settings · Documentation" : "设置 · 文档",
}
}
if (pathname === "/" || pathname === "/en-US") {
return {
description: english
? "Documentation for the my-shadcn-ui workspace packages."
: "my-shadcn-ui 工作区各个 package 的使用文档。",
title: english ? "my-shadcn-ui Documentation" : "my-shadcn-ui 文档",
}
}
return {
description: english
? "The requested documentation page does not exist."
: "请求的文档页面不存在。",
title: english ? "Page not found · Documentation" : "页面不存在 · 文档",
}
}