博客搭好顺便折腾了一下SEO,这里记录一下优化用到的插件和相关配置。

永久链接 hexo-abbrlink

  • 用途: hexo 默认是以文件名作为链接对搜索引擎不友好,使用这个插件可以生成永久链接,方便搜索引擎收录
  • 安装: pnpm install hexo-abbrlink --save
  • 配置:_config.yml中修改配置
1
2
3
4
5
6
7
#链接格式
permalink: posts/:abbrlink.html

# abbrlink config
abbrlink:
alg: crc32 #support crc16(default) and crc32
rep: hex #support dec(default) and hex

站点地图 hexo-generator-sitemap

  • 用途: 站点提交搜索引擎的时候需要提供站点地图
  • 安装: pnpm install hexo-generator-sitemap --save
  • 配置: 执行hexo g -d生成站点地图
  • 效果: 访问https://blog.code52.cn/sitemap.xml查看站点地图

RSS hexo-generator-feed

  • 用途: 生成 RSS方便别人订阅更新
  • 安装: pnpm install hexo-generator-feed --save
  • 配置:_config.yml中修改配置
1
2
3
4
feed:
type: atom
path: atom.xml
limit: 20

发布功能 hexo-deployer-git

  • 用途: 一键发布博客到GitHub Pages等平台
  • 安装: pnpm install hexo-deployer-git --save
  • 配置:_config.yml中修改配置
1
2
3
4
5
6
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
- type: git
repo: https://仓库地址
branch: master
  • 效果: 执行hexo clean && hexo generate -d && hexo deploy生成静态博客并发布

推送链接到搜索引擎 hexo-submit-urls-to-search-engine

  • 用途: 利用这个插件配合hexo发布可以在发布新博客的时候同步把链接推送搜索引擎
  • 安装: pnpm install hexo-submit-urls-to-search-engine --save
  • 说明: 使用前需要先到对应平台申请 token,申请地址:bing百度谷歌
  • 配置:_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
hexo_submit_urls_to_search_engine:
submit_condition: count #链接被提交的条件,可选值:count | period 现仅支持count
count: 10 # 提交最新的10个链接
period: 900 # 提交修改时间在 900 秒内的链接
google: 1 # 是否向Google提交,可选值:1 | 0(0:否;1:是)
bing: 1 # 是否向bing提交,可选值:1 | 0(0:否;1:是)
baidu: 1 # 是否向baidu提交,可选值:1 | 0(0:否;1:是)
txt_path: submit_urls.txt ## 文本文档名, 需要推送的链接会保存在此文本文档里
baidu_host: https://blog.code52.cn ## 在百度站长平台中注册的域名
baidu_token: ## 请注意这是您的秘钥, 所以请不要把它直接发布在公众仓库里!
bing_host: https://blog.code52.cn ## 在bing站长平台中注册的域名
bing_enable_indexnow: false # 是否用 indexNow 提交链接给必应: true (Yes) | false (No). 只有 2.1.1 及之后的版本才可以开启这个功能。
bing_token: ## 请注意这是您的秘钥, 所以请不要把它直接发布在公众仓库里!
google_host: https://blog.code52.cn ## 在google站长平台中注册的域名
google_key_file: file.json #存放google key的json文件,放于网站根目录(与hexo _config.yml文件位置相同),请不要把json文件内容直接发布在公众仓库里!
google_proxy: http://127.0.0.1:7897 # 向谷歌提交网址所使用的系统 http 代理,填 0 不使用
replace: 0 # 是否替换链接中的部分字符串,可选值:1 | 0(0:否;1:是)
find_what: https://blog.code52.cn
replace_with: https://blog.code52.cn

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
- type: git
repo: 地址
branch: master
- type: cjh_bing_url_submitter
- type: cjh_google_url_submitter
- type: cjh_baidu_url_submitter