diff options
| author | 2023-04-22 19:52:26 +0800 | |
|---|---|---|
| committer | 2023-04-22 19:52:26 +0800 | |
| commit | 4838df315931bb883f704ec3e1abe2685f296cdf (patch) | |
| tree | 57a8550c4cd5338f1126364bb518c6cde8d96e7d /docs/theme.config.js | |
| parent | db74ade0234a40c2120ad5f2a41bee50ce13de02 (diff) | |
| download | HydroRoll-4838df315931bb883f704ec3e1abe2685f296cdf.tar.gz HydroRoll-4838df315931bb883f704ec3e1abe2685f296cdf.zip | |
😀
Diffstat (limited to 'docs/theme.config.js')
| -rw-r--r-- | docs/theme.config.js | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/docs/theme.config.js b/docs/theme.config.js new file mode 100644 index 0000000..0704c09 --- /dev/null +++ b/docs/theme.config.js @@ -0,0 +1,178 @@ +import { useState, useEffect } from "react"; +import { useRouter } from "next/router"; +import { useConfig, useTheme } from "nextra-theme-docs"; +import { Footer } from "./components/Footer"; +import Navigation from "./components/Navigation"; +import HeaderLogo from "./components/HeaderLogo"; +import ExtraContent from "./components/ExtraContent"; +import { Discord, Github } from "./components/Social"; + +const SITE_ROOT = "https://turbo.build"; + +/** + * @type {import('nextra-theme-docs').DocsThemeConfig} + */ +const theme = { + sidebar: { + defaultMenuCollapseLevel: Number.POSITIVE_INFINITY, + }, + docsRepositoryBase: "https://github.com/vercel/turbo/blob/main/docs", + useNextSeoProps: function SEO() { + const router = useRouter(); + const { frontMatter } = useConfig(); + + let section = "Turbo"; + if (router?.pathname.startsWith("/pack")) { + section = "Turbopack"; + } + if (router?.pathname.startsWith("/repo")) { + section = "Turborepo"; + } + + const defaultTitle = frontMatter.overrideTitle || section; + + return { + description: frontMatter.description, + defaultTitle, + titleTemplate: `%s – ${section}`, + }; + }, + gitTimestamp({ timestamp }) { + // eslint-disable-next-line react-hooks/rules-of-hooks + const [dateString, setDateString] = useState(timestamp.toISOString()); + + // eslint-disable-next-line react-hooks/rules-of-hooks + useEffect(() => { + try { + setDateString( + timestamp.toLocaleDateString(navigator.language, { + day: "numeric", + month: "long", + year: "numeric", + }) + ); + } catch (e) { + // Ignore errors here; they get the ISO string. + // At least one person out there has manually misconfigured navigator.language. + } + }, [timestamp]); + + return <>Last updated on {dateString}</>; + }, + unstable_flexsearch: true, + unstable_staticImage: true, + toc: { + float: true, + extraContent: ExtraContent, + }, + font: false, + feedback: { + link: "Question? Give us feedback →", + }, + logo: HeaderLogo, + logoLink: false, + head: function Head() { + const router = useRouter(); + const { systemTheme = "dark" } = useTheme(); + const { frontMatter } = useConfig(); + const fullUrl = + router.asPath === "/" ? SITE_ROOT : `${SITE_ROOT}${router.asPath}`; + + const asPath = router.asPath; + + let ogUrl; + + if (asPath === "/") { + ogUrl = `${SITE_ROOT}/api/og`; + } else if (frontMatter?.ogImage) { + ogUrl = `${SITE_ROOT}${frontMatter.ogImage}`; + } else { + const type = asPath.startsWith("/repo") + ? "repo" + : asPath.startsWith("/pack") + ? "pack" + : ""; + const title = frontMatter.title + ? `&title=${encodeURIComponent(frontMatter.title)}` + : ""; + + ogUrl = `${SITE_ROOT}/api/og?type=${type}${title}`; + } + + return ( + <> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <link + rel="apple-touch-icon" + sizes="180x180" + href={`/images/favicon-${systemTheme}/apple-touch-icon.png`} + /> + <link + rel="icon" + type="image/png" + sizes="32x32" + href={`/images/favicon-${systemTheme}/favicon-32x32.png`} + /> + <link + rel="icon" + type="image/png" + sizes="16x16" + href={`/images/favicon-${systemTheme}/favicon-16x16.png`} + /> + <link + rel="mask-icon" + href={`/images/favicon-${systemTheme}/safari-pinned-tab.svg`} + color="#000000" + /> + <link + rel="shortcut icon" + href={`/images/favicon-${systemTheme}/favicon.ico`} + /> + <meta name="msapplication-TileColor" content="#000000" /> + <meta name="theme-color" content="#000" /> + <meta name="twitter:card" content="summary_large_image" /> + <meta name="twitter:site" content="@turborepo" /> + <meta name="twitter:creator" content="@turborepo" /> + <meta property="og:type" content="website" /> + <meta property="og:url" content={fullUrl} /> + <link rel="canonical" href={fullUrl} /> + <meta property="twitter:image" content={ogUrl} /> + <meta property="og:image" content={ogUrl} /> + <meta property="og:locale" content="en_IE" /> + <meta property="og:site_name" content="Turbo" /> + <link rel="prefetch" href="/repo" as="document" /> + <link rel="prefetch" href="/repo/docs" as="document" /> + <link rel="prefetch" href="/pack" as="document" /> + <link rel="prefetch" href="/pack/docs" as="document" /> + <link + rel="alternate" + type="application/rss+xml" + title="Turbo Blog" + href="https://turbo.build/feed.xml" + /> + </> + ); + }, + editLink: { + text: "Edit this page on GitHub", + }, + navbar: { + component: Navigation, + extraContent: ( + <> + <Github /> + <Discord /> + </> + ), + }, + search: { + placeholder: "Search documentation…", + }, + footer: { + component: Footer, + }, + nextThemes: { + defaultTheme: "dark", + }, +}; +export default theme; |
