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-md-h1

v1.0.11

Published

添加一级标题到 Markdown 文档

Readme

vitepress-plugin-md-h1

这是一个适用于 vitepress 的 Vite 插件,在 vitepress 启动后自动生成一级标题到 Markdown 文档开头处(假如 Markdown 文档没有设置过一级标题)。

说明:只在页面加载 Markdown 内容时生成一级标题,并不会真正修改 Markdown 文档内容。

插件默认只给 frontmatter.layout 不存在或者 frontmatter.layoutdoc 的 Markdown 注入一级标题,如果希望强制注入一级标题,可以使用 autoTitle 配置。

✨ Feature

  • 🚀 将 frontmatter.title 或「文件名」作为一级标题注入到 Markdown 文档开头处

🕯️ Install

安装 vitepress-plugin-md-h1 插件

# 推荐使用 pnpm
pnpm i vitepress-plugin-md-h1
# or yarn
yarn add vitepress-plugin-md-h1
# or npm
npm install vitepress-plugin-md-h1

添加 vitepress-plugin-md-h1 插件到 .vitepress/config.ts

import { defineConfig } from "vitepress";
import MdH1 from "vitepress-plugin-md-h1";

export default defineConfig({
  vite: {
    plugins: [MdH1()],
  },
});

说明:该插件仅限项目启动时生效,已改动或新添加的 Markdown 需要重启项目才能生效。

🛠️ Options

| name | description | type | default | | ------------ | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------- | ------- | ----- | --- | | ignoreList | 忽略的文件路径,支持正则表达式 | string[] | [] | | beforeInject | 添加一级标题前的钩子,如果返回 false,则不添加一级标题,如果返回 string,则使用返回值作为一级标题,string 必须是一个非空字符串 | (frontmatter: Record<string, any>, id: string, title: string) => boolean | string | void | |

📘 TypeScript

🛠️ Options

export interface MdH1Option {
  /**
   * 忽略的文件路径,支持正则表达式
   *
   * @default []
   */
  ignoreList?: Array<RegExp | string>;
  /**
   * 添加一级标题前的钩子,如果返回 false,则不添加一级标题,如果返回 string,则使用返回值作为一级标题,string 必须是一个非空字符串
   */
  beforeInject?: (frontmatter: Record<string, any>, id: string, title: string) => boolean | string | void;
}

📖 Usage

如果不希望某个 Markdown 文档注入一级标题,请在该文档 frontmatter 配置:

---
autoTitle: false
---

如果不希望某个目录下的所有 Markdown 文档注入一级标题,则使用 ignoreList 配置项:

import { defineConfig } from "vitepress";
import MdH1 from "vitepress-plugin-md-h1";

export default defineConfig({
  vite: {
    plugins: [
      MdH1({
        ignoreList: ["xxx"],
      }),
    ],
  },
});

如果想根据文档的 frontmatter 或者文档路径来决定是否允许注入一级标题,则使用 beforeInject 钩子:

import { defineConfig } from "vitepress";
import MdH1 from "vitepress-plugin-md-h1";

export default defineConfig({
  vite: {
    plugins: [
      MdH1({
        beforeInject: (frontmatter, id, title) => {
          // 根据 frontmatter 的某个值判断
          if (frontmatter.catalogue) return false;

          // 根据文档路径判断
          if (id.includes("@page")) return false;

          // 根据即将生成的一级标题判断
          if (title === "简介") return false;
        },
      }),
    ],
  },
});

beforeInject 钩子除了支持返回 false 来决定是否注入一级标题,也可以返回一个字符串替换为一级标题。

import { defineConfig } from "vitepress";
import MdH1 from "vitepress-plugin-md-h1";

export default defineConfig({
  vite: {
    plugins: [
      MdH1({
        beforeInject: (frontmatter, id, title) => {
          // 根据 frontmatter 的某个值判断
          if (frontmatter.archivesPage) return "归档页";

          // 根据即将生成的一级标题判断
          if (title === "简介") return "文档简介";
        },
      }),
    ],
  },
});

🉑 License

MIT License © 2025 Teeker