npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vitepress-plugin-sidebar-permalink

v1.6.0

Published

VitePress 自动生成 sidebar 和 permalink rewrites 的插件

Readme

vitepress-plugin-sidebar-permalink

VitePress 插件:自动生成 sidebar 侧边栏和 permalink rewrites 映射,支持数字前缀排序、collapsed 配置、permalink 匹配高亮、目录/文件名美化等。

用法

// .vitepress/config.ts
import { defineConfig } from 'vitepress'
import SidebarPermalinkPlugin, { generatedSidebar, generatedRewrites } from 'vitepress-plugin-sidebar-permalink'

export default defineConfig({
  vite: {
    plugins: [
      SidebarPermalinkPlugin({
        root: 'docs', // 根目录,默认为 'docs'
        dir: 'docs/articles', // md文件所在目录,默认为 'docs/articles'
        rewritesPath: 'docs/rewrites.json', // 重写规则文件路径,默认为 
        'docs/rewrites.json'
        rewrites: {}, // 直接提供重写规则,一般为rewritesJson.rewrites
        options: { collapsed: true }, // 侧边栏是否折叠,默认为 true
        ignoreDirs: {
          rewriteIgnores: [], // 默认重写规则忽略目录
          sidebarIgnores: [] // 默认侧边栏忽略目录
        },
        navLinks: [ // 可选,导航栏配置
          { text: '组件', link: '/pages/fe4521' },
          { text: '后端', link: '/pages/571de5' },
          { text: '资源', link: '/pages/87a36a' }
        ],
      })
    ]
  },
  // 使用插件自动生成的侧边栏和重写规则
  rewrites: generatedRewrites,
  themeConfig: {
    sidebar: generatedSidebar
  }
})
  • 插件会在启动时生成侧边栏和重写规则,优先从rewrites参数获取重写规则,其次从生成的json文件读取,建议生成json文件后配置该参数

  • 通过导出的 generatedSidebargeneratedRewrites 变量直接使用生成的配置

  • 插件默认忽略目录

    {
      // 默认重写规则忽略目录
      rewriteIgnores: ['.vitepress', 'node_modules', 'public', 'dist'], 
      // 默认侧边栏忽略目录
      sidebarIgnores: ['.vitepress', 'node_modules', 'public', 'dist', '@pages', 'index.md']
    }

修改侧边栏样式

// .vitepress/theme/index.ts
import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import 'vitepress-plugin-sidebar-permalink/index.css'

export default {
  extends: DefaultTheme,
  enhanceApp({ router }) {
    // 自定义增强逻辑
  }
} satisfies Theme

特性

  • 全自动生成:插件启动时自动生成侧边栏和重写规则,无需手动调用
  • 自动生成侧边栏:支持数字前缀排序、collapsed 配置、permalink 匹配高亮、目录/文件名美化
  • 自动生成重写规则:支持 permalink 映射,方便管理文档 URL
  • 支持私有页面:通过 frontmatter 中的 private: true 标记私有页面(只适配本站主题包,配置后即可开启加密,访问需登录,单独使用无效
  • 支持隐藏侧边栏项:通过 frontmatter 中的 sidebar: false 可以在侧边栏中隐藏特定页面
  • 灵活配置:可自定义忽略目录、折叠状态、导航链接等
  • 保持与 VitePress 官方 sidebar 配置行为一致
  • 支持直接导出配置:通过 generatedSidebargeneratedRewrites 直接使用生成的配置

配置选项

| 选项 | 类型 | 默认值 | 说明 | |------|------|--------|------| | root | string | 'docs' | 根目录路径 | | dir | string | 'docs/articles' | md文件所在目录 | | rewritesPath | string | 'docs/rewrites.json' | 重写规则文件路径 | | rewrites | Record<string, string> | undefined | 直接提供重写规则(不从文件读取) | | options | { collapsed: boolean } | { collapsed: true } | 侧边栏配置选项 | | navLinks | array | undefined | 导航栏配置 | | ignoreDirs | IgnoreDirs | 见上文 | 忽略目录配置 |