创作集约 544 字
hexo-filter-nofollow - Hexo 官方的 nofollow 插件

hexo-filter-nofollow 是一个自动为 Hexo 博客中的外链添加 rel="external nofollow noreferrer" 的插件。
插件目前由我和 curbeng 维护,已成为 Hexo 官方插件。
简介
hexo-filter-nofollow 会为你的博客中的外链自动添加 rel="external nofollow noreferrer" 属性,从而 改善你的网站的安全性和 SEO。
安装
$ npm i hexo-filter-nofollow --save 如果你使用 yarn 作为你的 Hexo 的包管理器,你也可以使用下述命令:
$ yarn add hexo-filter-nofollow 选项
nofollow:
enable: true
field: site
exclude:
- 'exclude1.com'
- 'exclude2.com' - enable - 是否启用插件,默认值为
true - field - 插件的处理范围,默认值为
site,可选post或sitepost- 仅处理文章内容site- 处理全站所有页面
- exclude - 域名白名单,不同的子域名视为不同的域名(如
www)exclude1.com不包括www.exclude1.com或en.exclude1.com
从 hexo-autonofollow 迁移
hexo-autonofollow 是由 liuzc 在 2016 年开发的为 Hexo 所有页面中的外链添加 rel="external nofollow" 属性的插件。hexo-filter-nofollow 相比 hexo-autonofollow 有以下区别:
enable配置 默认值为true,默认启用插件- 新增
field配置,支持设置插件处理范围 - 移除 cheerio 依赖,使用正则表达式匹配
- 已加入 Hexo 官方插件,由 Hexo 官方团队维护
如果你之前已经安装了 hexo-autonofollow,可以直接卸载 hexo-autonofollow 并安装 hexo-filter-nofollow。hexo-filter-nofollow 的配置和 hexo-autonofollow 的配置完全兼容。
一些题外话
虽然 hexo-autonofollow 三年没有更新了,但是除了 cheerio 版本过旧、存在安全漏洞以外,其实并不影响使用。NodeJS 上没有高性能的 DOM 解析库;cheerio 已经是最快的了,但是用来遍历 Hexo 生成的所有页面时耗费的时间仍然堪忧。Hexo 已经提出了 使用 Native API 代替 cheerio 的提案,hexo-filter-nofollow 正是 使用正则表达式代替 DOM 解析库 的一次实验和尝试。