技術部落格初體驗:Docusaurus設定真的很複雜啊(佈置篇)
· 閱讀時間約 6 分鐘
隨著自訂的增加,佈景的設定也越來越多,docusaurus.confg.ts 太長了怎麼辦!?每次要找東西都好辛苦~
自訂配置
- 首先我們將 themeConfig 從 docusaurus.config 中抽離出來,另外放到專案目錄下的 config 底下
docusaurus.confg.ts
import themeConfig from './config/themeConfig';
const config: Config = {
// Theme configurations
themeConfig,
};
config/themeConfig.ts
// 引入相關需要使用的套件
import type * as Preset from '@docusaurus/preset-classic';
import { themes as prismThemes } from 'prism-react-renderer';
const themeConfig = {} satisfies Preset.ThemeConfig;
// 將設定export出去
export default themeConfig;
- 將佈景的設定放置於 config 底下,並開始制定相關佈景,首先更換自己的 image 和 favicon
config/themeConfig.ts
const themeConfig = {
// 可以更換成自己想要的帳片和icon,在網站縮圖或轉發連結或網頁縮圖都會使用到
image: 'images/icon/chao_en_huang_icon.png',
favicon: 'images/icon/favicon.ico',
};
- Docs,在 docs 的分業中,有沒有要自動縮合
config/themeConfig.ts
const themeConfig = {
// Docs
docs: {
sidebar: {
autoCollapseCategories: true,
},
},
};
- Navbar,這裡可以設定網頁上面的分頁標籤,設定名字、Logo,並設定要有那些分頁
config/themeConfig.ts
const themeConfig = {
// Navbar
navbar: {
title: 'Chao-En',
logo: {
alt: 'My Site Logo',
src: 'images/icon/apple-touch-icon.png',
},
// hideOnScroll: true,
items: [
{
// 設定自己想要跳轉的頁面
to: '/about-me',
label: 'About Me',
position: 'left',
},
{
// 設定要是像doc樣子的sidebar
type: 'docSidebar',
sidebarId: 'notesSidebar', //在sidebars.ts中定義,如何生成sidebar
position: 'left',
label: 'Notes',
},
{
// 設定要是像doc樣子的sidebar
type: 'docSidebar',
sidebarId: 'researchSidebar', //在sidebars.ts中定義,如何生成sidebar
position: 'left',
label: 'Research',
},
{
// 設定部落格的分頁
to: '/blog',
label: 'Blog',
position: 'left',
},
{
// 增加github的連結在最右邊
href: 'https://github.com/koteruon',
label: 'GitHub',
position: 'right',
},
],
},
};