配置文件
示例配置
docusaurus.config.js
import { themes as prismThemes } from 'prism-react-renderer';
/** @type {import('@docusaurus/types').Config} */
const config = {
title: '在线知识库',
tagline: 'www.zxzsk.com',
favicon: 'img/书籍.png',
// 在这里设置您网站的生产环境URL
url: 'https://www.zxzsk.com',
// 设置您的网站服务的路径名,对于GitHub Pages部署,这通常为 ‘/’。
baseUrl: '/',
// 配置 build 过程中遇到无效链接时的行为。throw:抛出错误并停止。
onBrokenLinks: 'throw',
// 配置 build 过程中 Markdown 文件中遇到无效链接时的行为。warn:输出警告信息,但不会停止。
onBrokenMarkdownLinks: 'warn',
// 设置语言
i18n: {
defaultLocale: 'zh-Hans',
locales: ['en', 'zh-Hans'],
},
// 预设主题
presets: [
[
'classic', // 一个标准预设主题,适用于大多数文档和博客网站
/** @type {import('@docusaurus/preset-classic').Options} */
({
// docs:这个对象包含了文档部分的配置选项。
docs: {
//指定了一个侧边栏配置文件的路径,该文件定义了文档侧边栏的结构。
sidebarPath: './sidebars.js',
// 侧边栏目录折叠 = true 允许用户折叠sidebar上的目录
sidebarCollapsible: true,
// true 默认折叠所有目录,false 默认展开所有目录
sidebarCollapsed: true,
// 是否显示最后更新文档的时间
showLastUpdateTime: true,
routeBasePath: '/',
},
// blog: 这个对象包含了博客部分的配置选项。
blog: {
// 是否在博客文章页面上显示预计的阅读时间。
showReadingTime: true,
// 配置博客的RSS和Atom订阅源选项。
feedOptions: {
// type: ['rss', 'atom']: 指定生成订阅源的格式,这里同时生成了RSS和Atom格式。
type: ['rss', 'atom'],
// 是否启用XSLT样式表,用于美化订阅源的XML内容。
xslt: true,
},
// 配置编译过程 检测博客文章是否配置最佳。
onInlineTags: 'warn',
onInlineAuthors: 'warn',
onUntruncatedBlogPosts: 'warn',
// 其他配置
blogSidebarCount: 'ALL',
blogSidebarTitle: '所有博客',
},
// theme: 这个对象包含了主题相关的配置选项。
theme: {
// 指定自定义CSS文件的路径,用于覆盖默认主题样式。
customCss: './src/css/custom.css',
},
// 谷歌分析插件
gtag: {
trackingID: 'G-XXX',
anonymizeIP: true,
},
}),
],
],
themes: ['@docusaurus/theme-mermaid', '@docusaurus/theme-live-codeblock'],
themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
docs: {
sidebar: {
hideable: true, //是否允许用户隐藏侧边栏
},
},
// 在此添加 algolia 搜索
// image: 项目的社交卡片图片,用于在社交媒体上分享链接时显示的预览图片。
image: 'img/docusaurus-social-card.jpg',
// 设置顶部导航栏
navbar: {
// 站点标题
title: '在线知识库',
// logo
logo: {
// alt: Logo图片的替代文本
alt: 'My Site Logo',
// src: Logo图片的文件路径。
src: 'img/书籍.png',
},
// 配置导航栏菜单
items: [
//外部链接
{
label: '读书',
position: 'right',
href: 'https://booklist.zxzsk.com',
},
{
label: '站点状态',
position: 'right',
href: 'https://uptime.zxzsk.com/status/zxzsk',
},
// 内部链接
{ to: '/blog', label: '博客+资讯', position: 'left' },
],
},
// 配置站点底部显示信息
footer: {
// 底部主题
style: 'dark',
// 底部链接
links: [
{
title: '站点切换',
items: [
{
label: '读书',
href: 'https://booklist.zxzsk.com',
},
{
label: '服务器状态',
href: 'https://uptime.zxzsk.com/status/zxzsk'
},
],
},
],
// 配置版权信息,这里使用了模板字符串来插入当前年份。
copyright: `版权所有© ${new Date().getFullYear()} 在线知识库(www.zxzsk.com) <br /> <a style="color:#aaa" href="https://docusaurus.io/zh-CN/">build by Docusaurus</a>`,
},
// 配置代码主题
prism: {
// 明亮主题:github主题有额外加成
theme: prismThemes.github,
// 夜间主题:dracula不错
darkTheme: prismThemes.dracula,
// 添加语法高亮额外支持的语言
additionalLanguages: ['bash', 'ini'],
},
}),
// markdown插件支持
markdown: {
// 美人鱼
mermaid: true,
// 解析器 md | mdx | detect
format: 'detect',
},
};
export default config;
示例配置
sidebars.js
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
localSidebar: [{ type: 'autogenerated', dirName: '.' }],
};
export default sidebars