1.0.2 • Published 7 months ago
vitepress-plugin-sidebar-generator v1.0.2
VitePress Plugin - Sidebar Generator
This VitePress plugin automatically generates and updates the sidebar for your documentation based on the structure of your Markdown files.
Features
- Updates the VitePress config before it is resolved.
- Watches for changes in your Markdown files and automatically updates a
sidebar.json
file.
Installation
Install the plugin via npm:
npm install vitepress-plugin-sidebar-generator --save-dev
Usage
- Configure your VitePress project.
- Create a sidebar.json file (the plugin will look for it in docs/.vitepress/sidebar.json by default) with an empty object. An existing sidebar configuration will work as well; just copy/paste it into a .json file.
Create a configuration object with the following options:
docsDir
(default: "docs"): Specify the documentation directory.includeDirs
(default: []): List of directories to include in the sidebar.ignoreFiles
(default: []): List of files to ignore.collapsible
(default: true, optional): Enable collapsible sections.collapsed
(default: false, optional): Set sections to be initially collapsed.sidebarFile
(default: "docs/.vitepress/sidebar.json", optional): Define the path for the generated sidebar file.
Import and use the plugin in your VitePress configuration:
import sidebar from './sidebar.json';
import sidebarGenerator from "vitepress-plugin-sidebar-generator";
export default defineConfig{
...
themeConfig: {
...
sidebar: sidebar
},
vite: {
plugins: [
sidebarGenerator({
docsDir: "docs",
includeDirs: ["components"],
}),
],
}
}
License
This project is licensed under the MIT License. See the LICENSE file for details.