vitepress-generate-sidebar
Version:
Vitepress generator sidebar based on file and directory structure.
136 lines (107 loc) • 2.8 kB
Markdown
Generator sidebar for [Vitepress](https://github.com/vuejs/vitepress) based on file and directory structure.
This pkg extends [vitepress-plugin-autobar](https://github.com/luciozhang/vitepress-plugin-autobar.git), Continuous integration requires an online build, so this package is released.
```shell
npm install -D vitepress-generate-sidebar
```
```javascript
getSideBar(rootDir = './', options?: Options)
```
- **rootDir**: `string` Directory to get configuration for
- **options**: `Options`Option to create configuration
Returns `sidebar` configuration for VitePress calculated using structure of directory and files in given path.
Type of Options:
```typescript
interface Options {
ignoreDirectory?: Array<string>, // Directoty path to ignore from being captured.
ignoreMDFiles?: Array<string>, // File path to ignore from being captured.
}
```
```javascript
import { getSideBar } from 'vitepress-plugin-autobar'
module.exports = {
// ...
themeConfig: {
// ...
sidebar: getSideBar("./docs"),
},
};
```
You can pass options to keep some path out of the sidebar.
```javascript
import { getSideBar } from 'vitepress-plugin-autobar'
module.exports = {
// ...
themeConfig: {
// ...
sidebar: getSideBar("./docs", {
ignoreMDFiles: ['index'],
ignoreDirectory: ['node_modules'],
}),
},
};
```
You directory may be like this.
```shell
.
├─ docs
│ ├─ .vitepress
│ │ └─ config.js
│ ├─ 01.Introduction
│ │ └─ START.md
│ ├─ 02.Utils
│ │ └─ dateUtil.md
│ │ └─ storeUtil.md
│ └─ index.md
```
- [x] Then `getSideBar` will return sidebar data like this. It will work well for vitepress.
- [x] Sidebar will order by file path.
- [x] Number in the file path will be removed.
```json
[
{
"text":"Introduction",
"items":[
{
"text":"START",
"link":"01.Introduction/START"
}
]
},
{
"text":"Utils",
"items":[
{
"text":"dateUtil",
"link":"02.Utils/dateUtil"
},
{
"text":"storeUtil",
"link":"02.Utils/storeUtil"
}
]
},
{
"text":"Index",
"items":[
{
"text":"Index",
"link":"index"
}
]
}
]
```
[](https://vitepress.vuejs.org/config/theme-configs#sidebar)
If vitepress supports plugins, this component will extend the functionality of plugins.
MIT
Copyright (c) 2022-present, luciozhang