next-theme/hexo-word-counter

GitHub: next-theme/hexo-word-counter

一个用 Rust 编写的高性能 Hexo 插件,用于高效统计文章字数和估算阅读时间。

Stars: 36 | Forks: 7

# Hexo 字数统计 [![Build Status](https://img.shields.io/github/actions/workflow/status/next-theme/hexo-word-counter/linter.yml?branch=main&style=for-the-badge)][github-url] [![npm-image]][npm-url] [![hexo-image]][hexo-url] [![lic-image]](LICENSE) 为 Hexo 博客中的文章提供字数统计和预计阅读时间。 字数统计基于 [Unicode® Standard Annex #29](https://www.unicode.org/reports/tr29/)。因此,当文章内容中包含多种语言时,总字数也能被准确统计。 凭借 Rust 的强大性能,此插件比几乎所有提供类似功能的其他 Hexo 插件都更快。请参阅下方的 [基准测试](#Benchmark)。 ## 安装说明 ![size-image] [![dm-image]][npm-url] [![dt-image]][npm-url] ``` npm install hexo-word-counter hexo clean ``` ## 使用方法 你可以在 **Hexo 的 `_config.yml` 文件**(位于你博客的根目录)中设置 hexo-word-counter 的选项: ``` symbols_count_time: symbols: true time: true total_symbols: true total_time: true exclude_codeblock: false wpm: 275 suffix: "mins." ``` 如果未指定 `symbols_count_time` 选项,则将使用默认参数。 ### 参数说明 * `wpm` – 每分钟字数(Words Per Minute)。默认值:`275`。你可以在此处查看相关说明 [此处](https://wordcounter.net)。 * 慢速阅读者 ≈ `200` * 正常速度 ≈ `275` * 快速阅读者 ≈ `350` * `suffix` – 如果预计阅读时间少于 60 分钟,将添加此后缀作为字符串参数。\ 如果未定义,默认将使用 `mins.`。 * `exclude_codeblock` – 允许排除代码块内的所有内容,以获得更精确的字数统计。\ 如果未定义,默认将使用 `false`。 **给中文用户的提示:** 如果你大多数情况下使用中文撰写文章(没有混杂英文),建议将 `wpm` 设置为 `300`。\ 但是,如果你经常在文章中中英混杂,将 `wpm` 设置为 `275` 会比较合适。 ### 针对 NexT 主题 此插件已集成到 «NexT» 主题中,在主 Hexo 配置中启用插件后,你可以在 NexT 配置中调整选项: ``` post_meta: item_text: true symbols_count_time: separated_meta: true item_text_total: false ``` ## 开发指南 开发此插件需要同时准备 Node.js 和 Rust 工具链。 ``` git clone https://github.com/next-theme/hexo-word-counter.git cd hexo-word-counter npm install ``` 你可以运行带或不带覆盖率反馈的测试: ``` npm test npm run test-cov ``` 你还可以在你的博客中安装开发版本: ``` cd blog npm i ../path/to/hexo-word-counter ``` ## 主题集成 如果你是主题开发者,可以使用以下代码来集成此插件。 ### 字数统计 语法根据主题的模板引擎不同而有所差异。 对于 Nunjucks / Swig: ``` {{ symbolsCount(post) }} ``` 对于 Ejs: ``` <%- symbolsCount(post) %> ``` 对于 Pug / Jade: ``` span=symbolsCount(post) ``` 在后续部分,我们使用 Nunjucks 语法作为示例。 ### 文章预计阅读时间 ``` {{ symbolsTime(post) }} ``` 或者使用预定义参数: ``` {{ symbolsTime(post, awl, wpm, suffix) }} ``` ### 总字数统计 ``` {{ symbolsCountTotal(site) }} ``` ### 总文章预计阅读时间 ``` {{ symbolsTimeTotal(site) }} ``` 或者使用预定义参数: ``` {{ symbolsTimeTotal(site, awl, wpm, suffix) }} ``` ## 基准测试 参见 [GitHub actions](https://github.com/next-theme/hexo-word-counter/actions/workflows/benchmark.yml)。 | 已安装插件 | `hexo g` 耗时 | | - | - | | 基准线 | 19.48s | | hexo-word-counter | 19.63s (+0.78%) | | [hexo-symbols-count-time](https://github.com/theme-next/hexo-symbols-count-time) | 19.86s (+1.99%) | | [hexo-wordcount](https://github.com/willin/hexo-wordcount) | 21.44s (+10.08%) | | [hexo-reading-time](https://github.com/ierhyna/hexo-reading-time) | 23.81s (+22.26%) |
标签:CMS安全, Hexo 插件, IPv6支持, JavaScript, MITM代理, npm 包, Rust, Unicode 标准, 内容分析, 单词计数, 博客工具, 可视化界面, 多语言支持, 安全测试框架, 性能优化, 检测绕过, 网络流量审计, 自定义脚本, 阅读时间估算