前言

以前没有怎么优化过seo、站点地图、rss订阅链接、robots 文件,一个都没有写过,不过今年打算重启博客了,自然这些改加上的东西都需要加一下了。

前前后后半年多吧,陆陆续续的,把这些玩意补齐了,但看了很多文章都写的补全,我就只好在来全部整理一下了。

一些插件

正文

添加robots.txt

可以直接在hexo 项目下的source添加robots.txt

比如说我的配置,让百度爬虫抓取百度专属的网站地图,其他搜索引擎直接抓取普通的网站地图。

1
2
3
4
5
6
7
8
User-agent: Baiduspider

Sitemap: https://blog.ning.moe/baidusitemap.xml

User-agent: *
Disallow:

Sitemap: https://blog.ning.moe/sitemap.xml

插件的使用和配置

安装

上述所有的插件的安装命令都类似 npm install <插件名字> --save 例如

1
npm install hexo-generator-feed --save

但就百度地图的插件稍微特殊:

1
npm install [email protected] --save

配置

至于配置可以访问GitHub的插件仓库地址,readme 会告诉你们这么配置,如果你很懒的话,我这边放上我的配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 配置网站地图
sitemap:
path: sitemap.xml
# 配置百度专属地图(真臭不要脸)
baidusitemap:
path: baidusitemap.xml
# Extensions
plugins:
hexo-generator-feed
#Feed Atom
feed:
type: atom
path: atom.xml
limit: 20
# 为网站使用到的所有外链添加rel="noopener external nofollow noreferrer", 可以有效地加强网站SEO和防止权重流失
# field 是指定那些页面我指定的post 是所有文章全部启用,如果你想启动全站都屏蔽链接的话就是 site,如果你有友联的话慎用。
#exclude是放行这些域名下的。
nofollow:
enable: true
field: post
exclude:
- '*.misaka.pics'
- 'icp.gov.moe'

hexo-submit-urls-to-search-engine 稍微有些特殊(我更倾向于你先去看看原来的教程),建议在操作之前备份一下 _config.yaml ,请确保你的推送分支为你自己的分支deploy,当然这边也有一个bug就是在推送的是我这边是选择了main 作为我的主分支,但是推送过去的时候还是master 如果你遇到和我一样的问题建议去提出issues,还有一个就是bing 的推送貌似是坏掉的状态,但百度正常。

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
# hexo-submit-urls-to-search-engine 主动将 url 提交到 Google Bing Baidu 搜索
hexo_submit_urls_to_search_engine:
submit_condition: count #链接被提交的条件,可选值:count | period 现仅支持count
count: 10 # 提交最新的10个链接
period: 900 # 提交修改时间在 900 秒内的链接
google: 0 # 是否向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.ning.moe ## 在百度站长平台中注册的域名
baidu_token: <Token> ## 请注意这是您的秘钥, 所以请不要把它直接发布在公众仓库里!
bing_host: https://blog.ning.moe ## 在bing站长平台中注册的域名
bing_token: <Token> ## 请注意这是您的秘钥, 所以请不要把它直接发布在公众仓库里!
google_host: https://blog.ning.moe ## 在google站长平台中注册的域名
google_key_file: Project.json #存放google key的json文件,放于网站根目录(与hexo _config.yml文件位置相同),请不要把json文件内容直接发布在公众仓库里!
google_proxy: http://127.0.0.1:7890 # 向谷歌提交网址所使用的系统 http 代理,填 0 不使用
replace: 0 # 是否替换链接中的部分字符串,可选值:1 | 0(0:否;1:是)
# find_what: http://cjh0613.github.io/blog
# replace_with: https://cjh0613.com

# 推送git的配置
deploy:
- type: git
repo:
coding: https://github.com/biliblihuorong/biliblihuorong.github.io.git # 你的仓库地址
branch: main

# hexo-submit-urls-to-search-engine 添加本插件的配置项:
- type: cjh_google_url_submitter
- type: cjh_bing_url_submitter
- type: cjh_baidu_url_submitter

引用

hexo-filter-nofollow:https://github.com/hexojs/hexo-filter-nofollow

hexo-generator-feed:https://github.com/hexojs/hexo-generator-feed

hexo-submit-urls-to-search-engine:https://github.com/cjh0613/hexo-submit-urls-to-search-engine

hexo-generator-baidu-sitemap:https://github.com/coneycode/hexo-generator-baidu-sitemap

hexo-generator-sitemap:https://github.com/hexojs/hexo-generator-sitemap