博客修改日志

记录本网站Next的所有所有修改

安装node和hexo

官方hexo教程 https://hexo.io/zh-cn/docs/

下载Next 6主题

最简单的安装方式是直接克隆整个仓库:

1
2
$ cd hexo
$ git clone https://github.com/theme-next/hexo-theme-next themes/next

常用的hexo命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 生成静态文件
hexo g
# 在本地打开服务器(使用默认端口4000)
hexo s
# 上传到GitHub Pages
hexo d

# 在本地4001端口打开服务器
hexo server -p 4001
hexo new [layout] <title>
hexo clean

hexo clean && hexo g && hexo d
hexo clean && hexo g && hexo s
hexo clean && hexo g && hexo server -p 4001

对主题配置文件进行修改

主题目录(具体路径为\themes\next\languages\zh_CN.yml)中增加

1
2
3
menu:
code: 学习
life: 生活

在主题目录中找到

1
2
3
4
5
menu:
home: / || home
code: /categories/学习/ || heartbeat
life: /categories/生活/ || calendar
categories: /categories/ || th

第78行 关闭Hexo支持,和主题

1
2
3
4
5
6
7
8
9
10
powered:
# Hexo link (Powered by Hexo).
enable: false
# Version info of Hexo after Hexo link (vX.X.X).
version: true
theme:
# Theme & scheme info link (Theme - NexT.scheme).
enable: false
# Version info of NexT after scheme info (vX.X.X).
version: true

第496行 添加汉字标准格式排版,Pangu支持

1
2
3
4
5
6
7
8
# Han Support
# Dependencies: https://github.com/theme-next/theme-next-han
han: true

# Pangu Support
# Dependencies: https://github.com/theme-next/theme-next-pangu
# For more information: https://github.com/vinta/pangu.js
pangu: true

第839行 设置点击图片可以全屏 fancybox: true

1
2
cd themes/next
git clone https://github.com/theme-next/theme-next-fancybox3 source/lib/fancybox

第872行 背景动画

1
2
3
4
5
cd themes/next
git clone https://github.com/theme-next/theme-next-canvas-nest source/lib/canvas-nest

canvas_nest:
enable: true

增加评论系统

第530行 https://ioliu.cn/2017/add-valine-comments-to-your-blog/

basic
1
2
3
4
5
6
7
8
9
10
11
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: M21sDSlu8gdmqbUdoKrXILYS-gzGzoHsz # your leancloud application appid
appkey: utJA9jhdKT7UHlpONQeaBlwD # 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
2
3
4
5
6
# 添加字数统计
symbols_count_time:
symbols: true
time: true
total_symbols: true
total_time: true

修改主题配置文件,搜索symbols_count_time,快速定位,修改成以下代码

1
2
3
4
5
symbols_count_time:
separated_meta: true
item_text_post: true
item_text_total: false
awl: 4

统计访客人数

修改第699行,现在有错误,应该是卜蒜子的插件出问题了

1
2
3
4
5
6
7
8
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

增加首行缩进

修改themes\next\layout\_partials\head\head.swig

1
2
3
4
5
6
7
8
9
// 特定段落(标志 00SuoJin00)缩进
$('p:contains("00SuoJin00")').each(function() {
var str = $(this).text();
if (str.match("^00SuoJin00")) {
var text = $(this).html();
$(this).css('text-indent', '2em');
$(this).html(text.replace('00SuoJin00', ''));
}
});

增加首页隐藏功能 有问题

修改themes\next\layout\_partials\head\head.swig

1
2
3
4
5
6
7
8
9
10
11
{% block content %}
<section id="posts" class="posts-expand">
{% for post in page.posts %}
{% if post.visible !== 'hide' %}
{{ post_template.render(post, true) }}
{% endif %}
{% endfor %}
</section>

{% include '../pagination.swig' %}
{% endblock %}

增加登陆密码

https://github.com/MikeCoder/hexo-blog-encrypt/blob/master/ReadMe.zh.md

  • 首先在 _config.yml 中启用该插件:
1
2
3
4
# Security
##
encrypt:
enable: true
  • 然后在你的文章的头部添加上对应的字段,如 password, abstract, message
1
2
3
4
5
6
7
8
9
---
title: hello world
date: 2016-03-30 21:18:02
tags:
- fdsafsdaf
password: Mike
abstract: Welcome to my blog, enter password to read.
message: Welcome to my blog, enter password to read.
---
  • 如果你想对 TOC 也进行加密,则在 article.ejs 中将 TOC 的生成代码修改成如下:
1
2
3
4
5
6
7
8
9
10
11
<% if(post.toc == true){ %>
<div id="toc-div" class="toc-article" <% if (post.encrypt == true) { %>style="display:none" <% } %>>
<strong class="toc-title">Index</strong>
<% if (post.encrypt == true) { %>
<%- toc(post.origin) %>
<% } else { %>
<%- toc(post.content) %>
<% } %>
</div>
<% } %>
<%- post.content %>
  • 然后使用 hexo clean && hexo g && hexo s,来查看效果。

增加版权说明

修改_config.yml

1
2
3
4
post_copyright:
enable: true
author: hiekay
copyright_text: 作者拥有版权,请注明出处转载。

给博客设置SEO

添加百度站长认证

主题目录中修改631行

1
2
3
# Baidu Webmaster tools verification setting
# See: https://ziyuan.baidu.com/site
baidu_site_verification: 4EmtGtNxNN