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-plume/plugin-auto-frontmatter

v1.0.0-rc.72

Published

The Plugin for VuePress 2 - auto frontmatter

Downloads

119

Readme

@vuepress-plume/plugin-auto-frontmatter

自动生成 *.md 文件的 frontmatter 配置。

Install

npm install @vuepress-plume/plugin-auto-frontmatter
# or
pnpm add @vuepress-plume/plugin-auto-frontmatter
# or
yarn add @vuepress-plume/plugin-auto-frontmatter

Usage

// .vuepress/config.[jt]s
import { autoFrontmatterPlugin } from '@vuepress-plume/plugin-auto-frontmatter'

export default {
  // ...
  plugins: [
    autoFrontmatterPlugin({
      formatter: {
        createTime(formatTime, file, matter) {
          if (formatTime)
            return formatTime
          return file.createTime
        }
      }
    })
  ]
  // ...
}

autoFrontmatterPlugin([options])

options

{ include?: string | string[]; exclude?: string | string[]; formatter: Formatter }

  • include include 匹配字符串或数组,匹配需要自动生成 frontmatter 的 md文件。 默认预设为 ['**/*.md']

  • exclude exclude 排除不需要的文件 默认预设为: ['!.vuepress/', '!node_modules/']

  • formatter 配置frontmatter每个字段的生成规则。

    interface MarkdownFile {
      filepath: string
      relativePath: string
      content: string
      createTime: Date
      stats: fs.Stats
    }
    
    interface FormatterFn<T = any, K = object> {
      (value: T, file: MarkdownFile, data: K): T
    }
    
    type FormatterObject<K = object, T = any> = Record<
      string,
      FormatterFn<T, K>
    >
    
    type FormatterArray = {
      include: string | string[]
      formatter: FormatterObject
    }[]
    
    type Formatter = FormatterObject | FormatterArray
    
    /**
     * formatterObj 对象中的 key 即为 frontmatter 配置中的key
     * 其方法返回的值将作为 frontmatter[key] 的值
     * .md
     * ---
     * createTime: 2022-03-26T11:46:50.000Z
     * ---
     */
    const formatterObj: Formatter = {
      createTime(formatTime, file, matter) {
        if (formatTime)
          return formatTime
        return file.createTime
      }
    }
    
    const formatterArr: Formatter = [
      {
        // 更精细化的匹配某个 md文件,支持glob 匹配字符串
        include: '**/{README,index}.md',
        // formatter 仅对 glob命中的文件有效
        formatter: {
          home(value, file, matter) {
            return value
          }
        },
      },
      {
        // 通配,如果文件没有被其他精细glob命中,
        // 则使用 通配 formatter
        // 如果是数组,必须有且用一个 include 为 * 的 项
        include: '*',
        formatter: {
          title(title) {
            return title || '默认标题'
          }
        }
      }
    ]

Why ?

  • 为什么需要这个插件?

    有时候在开发一些主题时,期望使用户更专注于内容的编写,尽可能减少配置性的工作,可以将一些重复性的必要的配置 直接通过本插件自动生成。