Customize Sidebar on VitePress Sites
Quick Reference
We have to add Objects here.
/.vitepress/config.mjs
mjs
import { defineConfig } from "vitepress";
export default defineConfig({
themeConfig: {
sidebar: [
// ==> Inside Here <==
],
},
});1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Adding a Single Link
Just add a signle Object if you want to add a normal link here.
/.vitepress/config.mjs
mjs
import { defineConfig } from "vitepress";
export default defineConfig({
themeConfig: {
sidebar: [
{
text: "Getting Started", // The text shown for the Sidebar UI
link: "/getting-started", // Markdown Files link
},
],
},
});1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
The text prop is simple. It will show the Text on the UI. But, About the link prop. link prop for the actual markdown files adress. Assuming your file structure will be like this:
Terminal
shell
$ tree -a --dirsfirst --gitignore
.
├── docs # This is the "source directory" which will be `/`
│ ├── public
│ │ └── icon.svg
│ ├── api-examples.md
│ ├── getting-started.md # And, This will become `/getting-started`
│ ├── index.md
│ └── markdown-examples.md
├── .vitepress
│ └── config.js
├── .gitignore
├── package.json
└── package-lock.json
4 directories, 9 filesAnd Thats how you link an internal file without the .md extention.
Adding a Section
/.vitepress/config.mjs
mjs
import { defineConfig } from "vitepress";
export default defineConfig({
themeConfig: {
sidebar: [
// ==> Inside here <==
],
},
});1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
A Section is just one object. Give it at least two keys:
text(string) – the heading of the sectionitems(array of objects) – the links
If you want the block to start collapsed, also add:
collapsed(boolean, set to true)
For Example:
/.vitepress/config.mjs
mjs
import { defineConfig } from "vitepress";
export default defineConfig({
themeConfig: {
sidebar: [
{ text: "Markdown Examples", link: "/markdown-examples" }, // Single Link
{ text: "Runtime API Examples", link: "/api-examples" }, // Single Link
{
text: "Docker",
items: [
{ text: "Get Started", link: "/examples/get-started" },
{ text: "Docker Fundamentls", link: "/examples/docker-fundamentals" },
],
},
],
},
});1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
This will add in a Section with Its dedicated links.
TIP
You can add as much single links or section with links as you want.