Files
code-docs/docusaurus.config.ts
T
2026-05-07 12:03:58 +08:00

186 lines
4.3 KiB
TypeScript

import type { Config } from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';
import { config as loadEnv } from 'dotenv';
import fs from 'fs';
import path from 'path';
loadEnv({ path: '.env.local' });
const techDocsHTML = fs.readFileSync(
path.join(__dirname, 'src/snippets/tech-docs.html'),
'utf-8',
);
const config: Config = {
title: 'CodeDocs 编程文档',
tagline: 'CodeDocs 编程文档 -- 这里是一些技术人的编程文档',
url: 'http://docs.yaoyuan.io/',
baseUrl: '/',
onBrokenLinks: 'throw',
onBrokenMarkdownLinks: 'warn',
favicon: 'img/favicon.ico',
organizationName: 'chuyaoyuan',
projectName: 'code-docs',
i18n: {
defaultLocale: 'zh-cn',
locales: ['zh-cn', 'en'],
localeConfigs: {
'zh-cn': {
label: '中文',
direction: 'ltr',
htmlLang: 'zh-CN',
},
en: {
label: 'English',
direction: 'ltr',
htmlLang: 'en-US',
},
},
},
themeConfig: {
// Only enable Algolia when API keys are provided
...(process.env.ALGOLIA_API_KEY && process.env.ALGOLIA_APP_ID ? {
algolia: {
apiKey: process.env.ALGOLIA_API_KEY,
appId: process.env.ALGOLIA_APP_ID,
indexName: 'code-docs',
contextualSearch: true,
searchParameters: {},
},
} : {}),
// Enable sidebar collapse/expand button (dyte-style)
docs: {
sidebar: {
hideable: true,
},
},
navbar: {
title: 'CodeDocs 编程文档',
logo: {
alt: 'CodeDocs 编程文档',
src: 'img/logo.svg',
},
items: [
// ── Mega Dropdown: 技术文档 (left-right panel, mirrors dyte SDK dropdown)
{
label: '技术文档',
type: 'dropdown',
className: 'tech-docs-dropdown',
position: 'left',
items: [
{
type: 'html',
value: techDocsHTML,
className: 'tech-docs-dropdown',
},
],
},
// ── Blog
{
to: '/blog',
label: 'Blog',
position: 'left',
},
// ── GitHub (right)
{
href: 'https://github.com/chuyaoyuan/code-docs',
label: 'GitHub',
position: 'right',
},
// ── Language toggle (right)
{
type: 'localeDropdown',
position: 'right',
},
],
},
footer: {
style: 'dark',
links: [
{
title: '文档',
items: [
{
label: 'CodeDocs',
to: '/docs/intro-docs',
},
],
},
{
title: '第三方链接',
items: [
{
label: 'Stack Overflow',
href: 'https://stackoverflow.com/',
},
{
label: 'Discord',
href: 'https://discordapp.com/',
},
],
},
{
title: '开发团队',
items: [
{
label: 'chuyaoyuan',
href: 'https://github.com/chuyaoyuan/',
},
{
label: 'zhangbohou',
href: 'https://github.com/BohouZhang',
},
],
},
{
title: '更多',
items: [
{
label: 'Blog',
to: '/blog',
},
{
label: 'GitHub',
href: 'https://github.com/chuyaoyuan/code-docs',
},
],
},
],
copyright: `Copyright © ${new Date().getFullYear()} Code Docs, Inc. 一些技术人的编程文档网站.`,
},
} satisfies Preset.ThemeConfig,
stylesheets: [
{
href: 'https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css',
type: 'text/css',
crossorigin: 'anonymous',
},
],
presets: [
[
'classic',
{
docs: {
sidebarPath: './sidebars.ts',
remarkPlugins: [remarkMath],
rehypePlugins: [rehypeKatex],
},
blog: {
showReadingTime: true,
},
theme: {
customCss: './src/css/custom.css',
},
} satisfies Preset.Options,
],
],
};
export default config;