个人博客搭建hexo+github(4):进阶配置

文章生成模板

命令

1
hexo new [layout] "postName"  #新建文章

按照layout格式,根据postName生成文章到hexo/source/_posts/postNmae.md.
layout为可选参数,默认为post,其他可选项在hexo/scaffolds目录下查看,md文件就是layout的名字。
可以自行添加新的layout或者更改现有的layout。

修改post.md:

1
2
3
4
5
6
7
8
9
10
11
title: {{ title }}
date: {{ date }}
updated: {{ date }}
categories:
- C1
- C2
tags: [T1, T2]
comments: true
layout: {{ layout }}
---
<!--more-->

注意:后面有空格。

添加RSS

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

    1
    $ npm install hexo-generator-feed –-save
  2. 修改 hexo配置文件_config.yml, add

    1
    2
    3
    4
    feed:
    type: atom
    path: atom.xml
    limit: 20

添加sitemap

Sitemap 的提交主要的目的,是要避免搜索引擎的爬虫没有完整的收录整个网页> 的内容,所以提交 Sitemap 是能够补足搜索引擎的不足,进而加速网页的收录
速度,达到搜寻引擎友好的目的。

1
2
$ npm install hexo-generator-sitemap --save
$ npm install hexo-generator-baidu-sitemap --save #this is for baidu

add below to _config.yml in the root dir of Hexo

1
2
3
4
sitemap:
path: sitemap.xml
baidusitemap:
path: baidusitemap.xml

添加robots.txt

robots.txt放在source文件夹下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# hexo robots.txt
User-agent: *
Allow: /
Allow: /archives/

Disallow: /vendors/
Disallow: /js/
Disallow: /css/
Disallow: /fonts/
Disallow: /vendors/
Disallow: /fancybox/

Sitemap: http://WuChenxu.github.io/sitemap.xml
Sitemap: http://WuChenxu.github.io/baidusitemap.xml

统计

使用百度统计,注册账号后,截取hm.js?后的字符串为Baidu Analytics ID.
在next主题配置文件中,修改baidu_analytics的值。

1
2
3
# Baidu Analytics ID
# 为百度统计提供脚本中 hm.js? 后字符串,非百度统计帐号
baidu_analytics:xxxx

留言

Valin

Valine 诞生于2017年8月7日,是一款基于Leancloud的快速、简洁且高效的无后端评论系统。

按照快速开始步骤,注册LeanCloud之后在主题配置文件使能valin即可。

next-theme/_config.yml
1
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: xxxxxx # your leancloud application appid
appkey: xxxxx # your leancloud application appkey
notify: true # mail notifier , https://github.com/xCss/Valine/wiki
verify: true # Verification code
placeholder: Just go go # comment box placeholder
avatar: mm # gravatar style
guest_info: nick,mail,link # custom comment header
pageSize: 10 # pagination size
visitor: true # 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

计数

使用不蒜子.

在最新的next主题(6.0)直接配置next主题即可,如下

next-theme/_config.yml
1
2
3
4
5
6
7
8
9
10
# Show Views/Visitors of the website/page with busuanzi.
# Get more information on http://ibruce.info/2015/04/04/busuanzi
busuanzi_count:
enable: true
total_visitors: true
total_visitors_icon: user
total_views: true
total_views_icon: eye
post_views: true
post_views_icon: eye

使用Valin

valin在留言基础上附加的计数功能。

next-theme/_config.yml
1
2
3
valine:
enable: true # When enable is set to be true, leancloud_visitors is recommended to be closed for the re-initialization
visitor: true

404页面

腾讯公益404生成代码嵌入404.html,放在

1
2
3
4
hexo\source
404.html

└─_posts

404.htmlview raw
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
<!DOCTYPE HTML>
<html>
<head>
<title>404 - WuChenxu'blog</title>
<meta name="description" content="404错误,页面不存在!">
<meta http-equiv="content-type" content="text/html;charset=utf-8;"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="robots" content="all" />
<meta name="robots" content="index,follow"/>
</head>
<body>
<br><!--
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>公益404</title>
</head>
<body>
<h1>404 Page Not Found</h1>
--><br><script type="text/javascript" src="//qzonestyle.gtimg.cn/qzone/hybrid/app/404/search_children.js" charset="utf-8" homePageUrl="https://wuchenxu.com" homePageName="回到我的主页"></script><br><!--
公益404介接入地址
益云公益404 http://yibo.iyiyun.com/Index/web404
腾讯公益404 http://www.qq.com/404
失蹤兒童少年資料管理中心404 http://404page.missingkids.org.tw
-->
<br>
</body>
</html>

html文件必须以utf-8格式保存,否则中文会出现乱码。
一定要是https,否则会被chrome拦截。

Reference:

  1. Hexo搭建Github-Pages博客
  2. NexT主题与Hexo更搭哦
  3. Valin