1.0.1 ā€¢ Published 1 year ago

@limy-org/vite-plugin-vitepress-auto-sidebar v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Features

  • šŸŖ„ Automatic sidebar generation
  • āœØ Title of files synchronized with sidebar
  • šŸš€ Automatic reload when files are deleted or title is modified
  • āœ”ļø Customizable configuration options (custom directory names, custom file sorting).

Installation

# pnpm
pnpm i @limy-org/vite-plugin-vitepress-auto-sidebar
# yarn
yarn add @limy-org/vite-plugin-vitepress-auto-sidebar
# npm
npm install @limy-org/vite-plugin-vitepress-auto-sidebar

Usage

// .vitepress/config.ts
import VitePluginAutoSidebar from "@limy-org/vite-plugin-vitepress-auto-sidebar";
export default defineConfig({
  vite: {
    plugins: [
      VitePluginAutoSidebar({
        sidebarResolved(value) {
          console.log(value);
          // do sort
          value["/dir2/"][0].items?.sort((a, b) => a.text - b.text);
          // rename
          value["/dir2/"][0].text = 'sorted'
        },
        ignores: ["index.md"],
        root: process.cwd(),
      }),
    ],
  },
});

How it work

ā”œā”€ā”€ .vitepress
ā”œā”€ā”€ dir1
ā”‚   ā”œā”€ā”€ dir1-1
ā”‚   ā”‚   ā”œā”€ā”€ 1.md
ā”‚   ā”‚   ā”œā”€ā”€ 2.md
ā”‚   ā”‚   ā””ā”€ā”€ dir1-1-1
ā”‚   ā”‚       ā””ā”€ā”€ 1.md
ā”‚   ā””ā”€ā”€ dir1-2
ā”‚       ā””ā”€ā”€ 1.md
ā”œā”€ā”€ dir2
ā”‚   ā””ā”€ā”€ 2-2
ā”‚       ā”œā”€ā”€ 2.md
ā”‚       ā””ā”€ā”€ 3.md
ā”œā”€ā”€ index.md
ā”œā”€ā”€ node_modules
ā””ā”€ā”€ package.json

TO


{
  "/dir2/": [
    {
      "text": "2-2",
      "collapsed": false,
      "items": [
        {
          "text": "2-2",
          "link": "/dir2/2-2/3.md"
        },
        {
          "text": "222",
          "link": "/dir2/2-2/2.md"
        }
      ]
    }
  ],
  "/dir1/": [
    {
      "text": "dir1-2",
      "collapsed": false,
      "items": [
        {
          "text": "1-2",
          "link": "/dir1/dir1-2/1.md"
        }
      ]
    },
    {
      "text": "dir1-1",
      "collapsed": false,
      "items": [
        {
          "text": "2222",
          "link": "/dir1/dir1-1/2.md"
        },
        {
          "text": "1-1",
          "link": "/dir1/dir1-1/1.md"
        },
        {
          "text": "dir1-1-1",
          "collapsed": false,
          "items": [
            {
              "text": "1-1-1",
              "link": "/dir1/dir1-1/dir1-1-1/1.md"
            }
          ]
        }
      ]
    }
  ]
}
1.0.1

1 year ago

1.0.0

1 year ago