Customize Navbar of VitePress
Recap
Terminal
shell
tree -a --dirsfirst --gitignore
.
├── docs
│ ├── public
│ │ └── icon.svg
│ ├── api-examples.md
│ ├── index.md
│ └── markdown-examples.md
├── .vitepress
│ └── config.js
├── .gitignore
├── package.json
└── package-lock.json
4 directories, 8 filesIts simple. You can go to the official docs.
Just remember, Navbar will be customized inside of the /.vitepress/config.mjs
.vitepress/config.mjs
mjs
import { defineConfig } from "vitepress";
export default defineConfig({
// ...
themeConfig: {
nav: [
{ text: "Home", link: "/" },
{ text: "Examples", link: "/markdown-examples" },
],
// ...
},
// ...
});1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
Change Navbar Title
.vitepress/config.mjs
mjs
import { defineConfig } from "vitepress";
export default defineConfig({
// ...
themeConfig: {
siteTitle: 'My Custom Title'
// ...
},
// ...
});1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Add Navbar Icon
.vitepress/config.mjs
mjs
import { defineConfig } from "vitepress";
export default defineConfig({
// ...
themeConfig: {
logo: '/my-logo.svg'
// ...
},
// ...
});1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
INFO
Its just importing the svg from the /docs/public/icon.svg. So, just use the /icon.svg
Adding Links
.vitepress/config.mjs
mjs
import { defineConfig } from "vitepress";
export default defineConfig({
// ...
themeConfig: {
nav: [
{ text: "Home", link: "/" },
{ text: "Examples", link: "/markdown-examples" },
{ text: "Docs", link: "/api-examples" },
],
// ...
},
// ...
});1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
Adding a link is just adding an object.
Adding a Dropdown
.vitepress/config.mjs
mjs
import { defineConfig } from "vitepress";
export default defineConfig({
// ...
themeConfig: {
nav: [
{ text: "Home", link: "/" },
{ text: "Examples", link: "/markdown-examples" },
{ text: "Docs", link: "/api-examples" },
{
text: "Dropdown Menu",
items: [
{
text: "Section Title",
items: [
{ text: "Section A Item A", link: "..." },
{ text: "Section B Item B", link: "..." },
],
},
],
},
],
// ...
},
// ...
});1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Adding a dropdown is just adding an object which has an array.
Social Links
.vitepress/config.mjs
mjs
import { defineConfig } from "vitepress";
export default defineConfig({
// ...
themeConfig: {
// ...
socialLinks: [
{
icon: "github",
link: "https://github.com/MdSakifHossain/Ultimate-Manual",
},
],
// ...
},
// ...
});1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
TIP
If you wanna add more social links then go to the official docs. becaues its just a Manual for Future Me