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

doc-menu

v0.0.1

Published

自动生成页面索引

Downloads

4

Readme

页面文档锚点生成

通过引入一个 js,可帮助文章页面立刻生成对应的索引列表信息。

使用

在页面最顶端引入cssjs,注意:等页面内容加载完成后,执行DOC_MENU.init()初始化后,立即就会在页面右侧出现索引列表。

资源引用两种方式:1.直接引用在线cdn地址。2.将编译后的源码目录 lib, 拷贝到项目中。具体如下:

<html>
<head>

<link rel="stylesheet" href="https://unpkg.com/[email protected]/lib/doc-menu.css">
<script src="https://unpkg.com/[email protected]/lib/doc-menu.js"></script>

<!-- <link rel="stylesheet" href="./lib/doc-menu.css">
<script src="./lib/doc-menu.js"></script> -->

</head>

<body>

    <script>
        DOC_MENU.init(); // 初始化
    </script>
</body>
</html>

原理

js 自动获取 HTML 中的 h1|h2|h3 标签中的信息,生成对应的信息列表。

效果如下:

可配置参数

DOC_MENU.title = "目录"; // 标题
DOC_MENU.hashPrefix = "hash"; // hash 前缀
DOC_MENU._menuList = []; // 菜单列表信息
DOC_MENU._menuTreeList = []; // 菜单列表树状信息

/**
 * 初始化
 * @param isRender 是否直接渲染,默认true
 * @return 菜单列表信息
 */
DOC_MENU.init(isRender) // 可以不直接渲染,配合`render`函数可自定义操作

/**
 * 菜单模块渲染
 * @param menuList 菜单列表信息
 * [{tag:'h1',content:'标题一',hash:'页面中的锚点id',children:[{tag:'h1',content:'标题一',hash:'页面中的锚点id'}]}]
 */
DOC_MENU.render(menuList) // 可以单独渲染索引列表