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 🙏

© 2024 – Pkg Stats / Ryan Hefner

vuepress-plugin-auto-sidebar-navbar

v1.0.9

Published

VuePress2 插件 - 自动生成sidebar和navbar插件(auto sidebar and navbar)

Downloads

7

Readme

vuepress-plugin-auto-sidebar-navbar

介绍(Introduction)

这是为 vuepress v2 自动生成侧边栏和导航栏的插件。 插件支持功能如下:

  1. 自动生成sidebar和navbar。
  2. 根据文件内容自动排序。
  3. 支持自定义排序方法。

安装(Install)

## vuepress v2
npm i vuepress-plugin-auto-sidebar-navbar -D

快速使用(Usage)

VuePress v2 不再支持插件修改 sidebar,所以你需要在.vuepress/config.js自行引入生成的 sidebar.jsnavbar.js文件。

const { defaultTheme } = require('@vuepress/theme-default')
const navbar = require('./navbar.js')
const sidebar = require('./sidebar.js')
module.exports = {
  plugins: [
    ...,
    require('vuepress-plugin-auto-sidebar-navbar')({})
  ],
  theme: defaultTheme({
    ...,
    navbar, 
    sidebar, 
  })
}

插件默认参数

传参方式为:require('vuepress-plugin-auto-sidebar-navbar')(options),其中options默认为以下参数:

options = {
    skipSidebar: false, // 默认生成sidebar
    skipNavbar: false, // 默认生成navbar
    sidebarUrl: '.vuepress/sidebar.js', // sidebar路径
    navbarUrl: '.vuepress/navbar.js', // navbar路径
}

自动排序

  1. sidebar(侧边栏)根据md文件内容排序,排序规则为:autoSort: {number}中的number从小到大排序,其中number默认为 0。
  2. navbar(导航栏)根据目录中的README.md文件内容排序,排序规则为:autoNavSort: {number}中的number从小到大排序,其中number默认为 0。

sidebar为例,a.md内容如下:

---
autoSort: -1
---
# 文件a

b.md内容如下:

# 文件b

sidebar显示内容:

文件a
文件b

自定义规则排序

.vuepress/config.js中传入参数sortFn:

module.exports = {
  ...,
  plugins: [
    ...,
  	require('vuepress-plugin-auto-sidebar-navbar')({
  	sortFn: (a, b) => {
  		if (a.sort !== b.sort) return a.sort < b.sort ? -1 : 1
        	if (a.name !== b.name) return a.name < b.name ? -1 : 1
        	else if (a.createTime !== b.createTime) return a.createTime < b.createTime ? -1 : 1
        	else if (a.updateTime !== b.updateTime) return a.updateTime < b.updateTime ? -1 : 1
		},
	})
  ],
}