在上一篇文章十分钟hexo装进docker里,我们搞定了docker部署hexo的方式,但是默认样式总是不能让人满意,于是接下来继续折腾。
食用前提
本文的基础是已经搞定了hexo部署,同时对hexo有基本的了解。如果还不会部署可以参考十分钟hexo装进docker
基本配置
主题选择与安装
在hexo的官网上有很多主题可以选择,在搜索各种资料的时候,发现有相当部分的技术博客都是用next主题做的,而且界面还挺美观的,所以选择了使用这个主题。1
2$ cd hexo
$ git clone https://github.com/theme-next/hexo-theme-next themes/next
接下来进行基本的站点配置和主题配置,站点配置文件在_config.yml
,主题配置文件在themes/next/_config.yml
。我这边的基本配置参考了打造个性超赞博客Hexo+NexT+GitHubPages的超深度优化
站点配置
1 | # Site |
主题配置
1 | # Allow to cache content generation. Introduced in NexT v6.0.0. |
第三方配置
评论
经过调研,尝试了LiveRe之后发现被墙,转向使用leancloud1
2
3
4
5
6
7
8
9
10
11
12
13
14# Valine.
# You can get your appid and appkey from https://leancloud.cn
# more info please open https://valine.js.org
valine:
enable: true # When enable is set to be true, leancloud_visitors is recommended to be closed for the re-initialization problem within different leancloud adk version.
appid: # your leancloud application appid
appkey: # your leancloud application appkey
notify: false # mail notifier , https://github.com/xCss/Valine/wiki
verify: false # Verification code
placeholder: 留下你的评论 # comment box placeholder
avatar: mm # gravatar style
guest_info: nick,mail,link # custom comment header
pageSize: 10 # pagination size
visitor: false # leancloud-counter-security is not supported for now. When visitor is set to be true, appid and appkey are recommended to be the same as leancloud_visitors' for counter compatibility. Article reading statistic https://valine.js.org/visitor.html
评分
1 | # Star rating support to each article. |
统计访问
1 | # Show number of visitors to each article. |
SEO配置
百度谷歌收录
搜索验证1
site:blog.zhouzhaoping.com
在google的Search Console里选择推荐的Domain name provider方式,baidu则使用html标签验证1
2
3# Baidu Webmaster tools verification setting
# See: https://ziyuan.baidu.com/site
baidu_site_verification: XXXXX
添加站点地图
1 | npm install hexo-generator-sitemap --save |
在博客的站点配置文件_config.yml中添加以下代码1
2
3
4sitemap:
path: sitemap.xml
baidusitemap:
path: baidusitemap.xml
hexo g
之后就能看到sitemap.xml
和baidusitemap.xml
到https://ziyuan.baidu.com/linksubmit提交百度sitemap
到https://www.google.com/webmasters/tools/sitemap-list提交谷歌sitemap
添加蜘蛛协议
在站点source文件夹下新建robots.txt
文件1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16User-agent: *
Allow: /
Allow: /archives/
Allow: /tags/
Allow: /about/
Allow: /categories/
Disallow: /vendors/
Disallow: /js/
Disallow: /css/
Disallow: /fonts/
Disallow: /vendors/
Disallow: /fancybox/
Sitemap: http://blog.zhouzhaoping.com/sitemap.xml
Sitemap: http://blog.zhouzhaoping.com/baidusitemap.xml
到https://ziyuan.baidu.com/robots检测robots
到https://www.google.com/webmasters/tools/robots-testing-tool检测谷歌robots
其它配置
修改主题配置中的1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18# ---------------------------------------------------------------
# SEO Settings
# ---------------------------------------------------------------
# Canonical, set a canonical link tag in your hexo, you could use it for your SEO of blog.
# See: https://support.google.com/webmasters/answer/139066
# Tips: Before you open this tag, remember set up your URL in hexo _config.yml ( ex. url: http://yourdomain.com )
canonical: true
# Change headers hierarchy on site-subtitle (will be main site description) and on all post/pages titles for better SEO-optimization.
seo: true
# If true, will add site-subtitle to index page, added in main hexo config.
# subtitle: Subtitle
index_with_subtitle: true
# Automatically add external URL with BASE64 encrypt & decrypt.
exturl: true
百度统计
修改站点配置中的百度分析id1
2# Baidu Analytics ID
baidu_analytics:
id即https://tongji.baidu.com里代码管理部分如下的XXXXX1
2
3
4
5
6
7var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?XXXXX";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();