在 Hexo 下全局使用 ADHD 友好字体 text-vide

插件地址: https://www.npmjs.com/package/text-vide

安装插件

选一

  • npm i text-vide
  • yarn add text-vide
  • pnpm add text-vide

scripts 件夹

在项目根目录下创建一个新的文件夹 scripts

scripts 文件夹中添加插件文件

scripts 文件夹内添加插件文件,global-text-vide.js,下:

1
2
3
.
├── scripts
│ └── global-text-vide.js # 自定义插件文件

将以下代码复制到 global-text-vide.js 件中 (这里没处理一些特殊情况, 需要自行修改正则):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const { textVide } = require('text-vide');

// 也可以去注册到after_render:html, 但这里为了只改动 md 件, 册到 before_post_render 子,Markdown
hexo.extend.filter.register('before_post_render', function (data) {
// 处理 Markdown
if (data.source.endsWith('.md')) {
const options = {
sep: ['<b>', '</b>'], // 高亮分隔符
fixationPoint: 3, // 数值越低高亮的越多
};

let ignoreRegions = [];
let index = 0;

// Nunjucks 板、码块
data.content = data.content.replace(/`.*?`|{%.*?%}/g, match => {
// 将忽略的内容替换为占位符
ignoreRegions.push(match);
return `<!-- text-vide-ignore:#123;index++} -->`;
});

// 对非忽略区域应用 text-vide
data.content = data.content.split('\n').map(line => {
if (!line.startsWith('<!-- text-vide-ignore:')) {
return textVide(line, options); // text-vide
}
return line; // 保留占位符行
}).join('\n');

// 恢复忽略的区域
ignoreRegions.forEach((region, idx) => {
data.content = data.content.replace(`<!-- text-vide-ignore:#123;idx} -->`, region);
});
}
return data;
});

重新生成 Hexo

1
hexo clean && hexo g

Hello Hexo

Welcome to [Hexo](https://hexo.io/)! This is your very first post. Check [documentation](https://hexo.io/docs/) for more info. If you get any problems when using Hexo, you can find the answer in [troubleshooting](https://hexo.io/docs/troubleshooting.html) or you can ask me on [GitHub](https://github.com/hexojs/hexo/issues).

Quick Start

Create a new post

1
2
$ hexo new "My New Post"
$ hexo new post "My New Post" # (recommend)

More info: [Writing](https://hexo.io/docs/writing.html)

Run server

1
$ hexo server

More info: [Server](https://hexo.io/docs/server.html)

Generate static files

1
$ hexo generate

More info: [Generating](https://hexo.io/docs/generating.html)

Deploy to remote sites

1
$ hexo deploy

More info: [Deployment](https://hexo.io/docs/one-command-deployment.html)