plugin-reading-time
@renovamen/vuepress-plugin-reading-time@next 插件,用于在 VuePress 2 中统计文章字数和估计阅读时长。相比其它的阅读时长插件,本插件可以:
- 为中英文分别设置阅读速度
 - 选择将代码块或公式块中的字符排除在统计以外
 
安装
pnpm install @renovamen/vuepress-plugin-reading-time@next
yarn add @renovamen/vuepress-plugin-reading-time@next
npm install @renovamen/vuepress-plugin-reading-time@next
然后在 .vuepress/config.js 中引入这个插件:
const { readingTimePlugin } = require("@renovamen/vuepress-plugin-reading-time");
module.exports = {
  plugins: [
    readingTimePlugin()
  ]
}
使用
可以通过以下方法来获取 readingTime 数据:
import { pageData } from "@vuepress/client";
console.log(pageData.value.readingTime);
一个样例 readingTime 数据为:
{
  minutes: 12,  // 阅读时长估计
  words: 3500  // 文章字数
}
可以在文章的 frontmatter 中重写 readingTime 数据:
title: Hello Word
readingTime: { minutes: 3, words: 1500 }
配置项
excludes
不需要进行统计的页面路径,插件会通过正则表达式来将这些页面排除。如果指定了 includes 项,那么这一项无效。
- Type: 
Array<string> - Default: 
[] 
例子:
plugins: [
  readingTimePlugin({
    excludes: ["/docs/.*", "/posts/hello-word.html"]
  })
]
includes
需要进行统计的页面路径(正则表达式)。如果指定了这一项,那么 excludes 项无效。
- Type: 
Array<string> - Default: 
[] 
Example:
plugins: [
  readingTimePlugin({
    includes: ["/docs/.*"]
  })
]
wordsPerMinuteCN
一分钟可以阅读多少个中文字符。
- Type: 
int - Default: 
300 
例子:
plugins: [
  readingTimePlugin({
    wordsPerMinuteCN: 500
  })
]
wordsPerMinuteEN
一分钟可以阅读多少个英文字符。
- Type: 
int - Default: 
160 
例子:
plugins: [
  readingTimePlugin({
    wordsPerMinuteEN: 200
  })
]
excludeCodeBlock
是否排除所有代码块内的字符。
- Type: 
boolean - Default: 
false 
例子:
plugins: [
  readingTimePlugin({
    excludeCodeBlock: true
  })
]
excludeTexBlock
是否排除所有公式块内的字符。
- Type: 
boolean - Default: 
false 
例子:
plugins: [
  readingTimePlugin({
    excludeTexBlock: true
  })
]