Hexo博客:一些非常有用的插件
前言
使用框架Hexo搭建博客后,你可能需要一些功能,例如:对生成的文件进行压缩,生成站点地图,生成RSS订阅等等。面对官方的插件列表又有些无从下手,这里推荐一些,同时也是我在用的一些插件。
正文
下面示例的配置适用于2026年7月31日前的最新版插件,如果后期插件发生更新,请以官方文档为准。
页面生成器
除了Hexo init自动安装的生成器外,这里介绍一下RSS/Atom订阅生成器和sitemap生成器
hexo-generator-feed
官方仓库:https://github.com/hexojs/hexo-generator-feed
功能介绍:为你的博客生成feed,别人可以对你的博客进行订阅。
配置示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| feed: enable: true type: atom path: atom.xml limit: 20 hub: content: false content_limit: 140 content_limit_delim: ' ' order_by: -date icon: icon.png autodiscovery: true
|
为某个文章设置图片:
在文章的 front-matter 中设置
如果你博客也有文章封面图但是和这个配置名称不一样可以写个脚本自动转换。
hexo-generator-sitemap
官方仓库:https://github.com/hexojs/hexo-generator-sitemap
功能介绍:为站点产生一个标准格式的sitemap,方便搜索引擎收录
配置示例:
1 2 3 4 5 6 7 8 9
| sitemap: path: - sitemap.xml - sitemap.txt template: ./sitemap_template.xml template_txt: ./sitemap_template.txt rel: false tags: true categories: true
|
排除指定文章/页面
在文章的 front-matter 中设置
功能插件
hexo-abbrlink
官方仓库:https://github.com/ohroy/hexo-abbrlink
功能介绍:文章静态短链接,拒绝过长的链接
配置示例:
步骤 1:
修改 permalink(_config.yml)
1 2 3 4
| permalink: posts/:abbrlink/
permalink: posts/:abbrlink.html
|
步骤 2:
插件配置(_config.yml)
1 2 3 4 5 6 7
| abbrlink: alg: crc32 rep: hex drafts: false force: false writeback: true
|
效果示例:
1 2 3 4
| crc16 & hex → https: crc16 & dec → https: crc32 & hex → https: crc32 & dec → https:
|
hexo-blog-encrypt
官方仓库:https://github.com/D0n9X1n/hexo-blog-encrypt
功能介绍:给文章加密,限制文章的访问者范围
配置示例:
_config.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| encrypt: abstract: 有东西被加密了, 请输入密码查看. message: 您好, 这里需要密码. tags: - {name: tagName, password: 密码A} - {name: tagName, password: 密码B} wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
decryptButton: show: true text: 解密 autoSave: false stableSalt: false kdf: iterations: 250000 theme: default silent: true
|
文章 front-matter 用法
1 2 3 4 5 6 7 8 9 10 11 12
| --- title: Hello World date: 2016-03-30 21:18:02 password: hello abstract: 有东西被加密了, 请输入密码查看. message: 您好, 这里需要密码. wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试. theme: xray autoSave: true ---
文章正文……
|
特殊用法
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| # 对已打 Tag 加密的文章,单独取消加密: --- title: Callback Test tags: - A Tag should be encrypted password: "" # 空字符串 = 取消该篇的 Tag 加密 ---
# 解密后触发事件监听: <script> window.addEventListener('hexo-blog-decrypt', function() { // 解密完成后的回调 }); </script>
|
⚠️ 注意:v4 使用 AES-256-GCM,密文格式与 v3 不互通,升级需 hexo clean && hexo generate;生产环境必须 HTTPS(Web Crypto API 要求安全上下文)。
hexo-safego
官方仓库:https://github.com/willow-god/hexo-safego
功能介绍:外链安全跳转,在要跳转外部链接时,进行提示说明
配置示例:
_config.yml
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 37 38 39 40 41 42 43 44 45
| hexo_safego: general: enable: true enable_base64_encode: true enable_target_blank: true
security: url_param_name: 'u' html_file_name: 'go.html' ignore_attrs: - 'data-fancybox'
scope: apply_containers: - '#article-container' apply_pages: - "/posts/" - "/devices/" exclude_pages:
whitelist: domain_whitelist: - "your-site.com"
appearance: avatar: /info/avatar.ico title: "网站名称" subtitle: "网站副标题" darkmode: auto countdowntime: 4 custom_css: /css/go.css leave_text: "您即将离开本站,跳转到:" countdown_text: "⚡将在{seconds}秒后跳转,请自行确认链接安全性" manual_confirm_text: "💡请自行确认链接安全后再继续跳转"
debug: enable: false
|
单页关闭(front-matter)
特别注意:
domain_whitelist:必须填入你的站点域名,否则站内链接也会被处理成跳转页
hexo-yam
官方仓库:https://github.com/curbengh/hexo-yam
功能介绍:静态资源压缩:HTML/JS/CSS/SVG/XML/JSON + gzip/brotli/zstd
配置示例:
_config.yml
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| minify: enable: true previewServer: true
html: enable: true priority: 10 verbose: false exclude: globOptions:
css: enable: true priority: 10 verbose: false exclude: - "*.min.css" level: 2
js: enable: true priority: 10 verbose: false exclude: - "*.min.js" compress: mangle: true output:
svg: enable: true priority: 10 verbose: false include: - "*.svg" - "!*.min.svg" plugins:
xml: enable: false priority: 10 verbose: false include: - "*.xml" - "!*.min.xml" removeComments: true
json: enable: false priority: 10 verbose: false include: - "*.json" - "!*.min.json"
gzip: enable: true priority: 10 verbose: false include: - "*.html" - "*.css" - "*.js" - "*.txt" - "*.ttf" - "*.atom" - "*.stl" - "*.xml" - "*.svg" - "*.eot" - "*.json" level: 9
brotli: enable: true priority: 10 verbose: false include: - "*.html" - "*.css" - "*.js" - "*.txt" - "*.ttf" - "*.atom" - "*.stl" - "*.xml" - "*.svg" - "*.eot" - "*.json" level: 11
zstd: enable: true priority: 10 verbose: false include: - "*.html" - "*.css" - "*.js" - "*.txt" - "*.ttf" - "*.atom" - "*.stl" - "*.xml" - "*.svg" - "*.eot" - "*.json" level: 3
|
glob 匹配注意
1 2 3 4 5
| exclude: - "*foo.html" - "**/bar/*/*.html" globOptions: basename: true
|
写在最后
你或许会觉得这是AI生成的——确实借助了AI做总结,但我人工核对、调整也花了不少时间,所有配置都和我博客实际使用的一模一样,并且尽可能详细地给出了可能用到的配置。希望对你有所帮助。
鸣心/Write