欢迎使用 Hexo,本文档将帮助您快速上手。Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。

安装Hexo

1
2
npm install -g hexo-cli

建立博客

1
2
3
4
5
6
7
8
hexo init <你所放置的文件地址>

cd <你所放置的文件地址>

npm install

npm install --save hexo-renderer-jade hexo-generator-feed hexo-generator-sitemap hexo-browsersync hexo-generator-archive

此时你就会看到以下的目录结构

img

这就是基础的目录了

这里就介绍几个关键的文件和文件夹

_config.yml

网站的配置的信息都存储在这里面,很关键的文件,文章后面会做到详细阐述

source

这里面是存放用户资源的地方,什么意思呢?
也就是博客内容都放在这里面
进到目录中,就会发现有一个 _post文件夹 ,这个文件夹就是之后的文档主要文件。

themes

主题文件夹

hexo常用的命令

新建文章

1
2
3
4
hexo new <文章标题> # 可以简写hexo n <文章标题>

hexo clean 清理缓存

生成静态文件

由于Hexo是用Node.js来进行页面渲染,所以需要生成对应的静态文件

1
2
hexo generate # 可以简写hexo g

启动本地服务器

每篇文章总得查看无论是编排、内容,所以我们需要测试,这时候我们就需要本地服务了

1
2
hexo server # 可以简写hexo s

但是运行之前需要确保已经安装 hexo-server 插件

1
2
npm install hexo-server --save

此时服务器就会开启4000端口供你使用,但是可能你的服务器端口被占用了,会提示以下错误

1
2
FATAL Port 4000 has been used. Try other port instead.

此时你需要切换一个端口

1
2
hexo s -p 5000 # -p 是可以指定端口的操作

部署网站

辛辛苦苦打理了这么久的博客,不上传到服务器上展(zhuang)示(bi)一下,怎么对得起自己

1
2
hexo deploy # 可以简写 hexo d

这里涉及到几个知识点

  • 需要先渲染博客,也就是hexo g(可以hexo g -d一步操作)
  • 还需要配置博客目录下 _config.yml 文件中的deploy模块
1
2
3
4
5
6
# 之后会教大家如何操作
deploy:
type: git
repo: <git地址>
branch: master

其余的命令实际上用到真的不多,万一需要,百度就可以了

安装主题

戳这里到Hexo的插件库

这几就看个人喜好了,俗人这就不一一举例了,基本上每一个都是大同小异的,就按俗人所使用的这个吧

该博客的主题hexo-theme-butterfly 是基于Molunerfinn的hexo-theme-melody的基础上进行开发的。

安装hexo-theme-butterfly

在博客的根目录

1
2
git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/Butterfly

或者想用最新的分支的话

1
2
git clone -b dev https://github.com/jerryc127/hexo-theme-butterfly.git themes/Butterfly

替换主题

博客根目录

1
2
vim _config.yml

然后将

1
2
theme: Butterfly

这时候就成为俗人首页的大致样子了。

博客配置

文章front-matter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
---
title:
date:
tags:
categories:
keywords:
description:
top_img: (除非特定需要,可以不寫)
comments: 是否展示评论系统(true.展示 false.不展示)
description: 节选,如果不填就默认从文章中选择配置的长度
cover: 首页缩略图
toc: 是否显示toc
toc_number: 是否显示toc数字
copyright: 是否显示版权
---

1
2
3
4
5
# 节选内容
auto_excerpt:
enable: true
length: 150

系统中英文替换

替换主题后你会发现首页的菜单一开始是英文名字,或者不是自己想要的样子,怎么办?
配置 _config.yml

1
2
language: zh-CN

但是有人反馈,此时还没有全量变更为中文

1
2
3
# 进入主题文件夹
cd themes/Butterfly

会发现这里也有一个 _config.yml 文件,这个文件是掌管整套系统主题相关的配置,个人觉得重要程度的比重要比前面博客根目录的同名文件要重要,当然缺一不可。

编辑这个文件

1
2
3
4
5
6
7
8
9
10
11
12
13
# 可以像俗人一样把原本的英文名修改成中文,这样就会完全解决切换不彻底问题
menu:
首页: / || fa fa-home
时间轴: /archives/ || fa fa-archive
留言板: /message/ || fa fa-coffee
标签: /tags/ || fa fa-tags
分类: /categories/ || fa fa-folder-open
链接: /link/ || fa fa-link
关于: /about/ || fa fa-heart
列表||fa fa-list:
- 音乐 || /music/ || fa fa-music
- 视频 || /movies/ || fa fa-film

这里如果需要新增菜单栏目的话,记得这样的规律

  • 名称 || 路径 || icon

新增菜单

此时发现点击页面都是空白

这时候就需要新增页面的操作了,但是注意这里的新增和新增文章不同,这里需要加上分类

1
2
3
# 新增标签
hexo new page tags

在博客的根目录访问

1
2
source/tags/index.md

发现这是一个文档文件

是的,基本上大同小异,但是要注意,由于主题的底层已经加上了对该页面的效果,所以需要遵循命名规范后修改文档

1
2
3
4
title: 标签
date: 2019-10-01 10:00:00
type: "tags"

此时首页的标签按钮已经展示对应的页面内容了,其余的页面同理。

友情链接

  1. 前往你的Hexo根目录
  2. 输入 hexo new page link
  3. 找到 source/link/index.md 这个文件
  4. 编辑这个文件
1
2
3
4
title: 链接
date: 2019-10-01 10:00:00
type: "link"

注意,主题中配置友情链接的位置不是在该文件本身,而是需要你去 创建 source/_data 目录,并且新建文件 link.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class:
class_name: 友情链接
link_list:
1:
name: 名称
link: 地址
avatar: 头像
descr: 描述
#2:
# name: xxxxxx
# link: https://www.xxxxxxcn/
# avatar: https://xxxxx/avatar.png
# descr: xxxxxxx

同时,可以在themes/Butterfly/_config.yml文件中,写上个人博客的信息,方便他人帮忙转载

1
2
3
4
5
6
7
8
9
Flink:
headline: 友情链接
info_headline: 我的Blog资料
name: Blog 名字: 俗俗俗俗俗人。
address: Blog 地址: https://blog.thatwang.com/
avatar: Blog 头像: https://blog.thatwang.com/img/avatar.png
info: Blog 简介: 做个俗人,知世俗,而不俗
comment: 如果需要交换链接,请给我留言,谢谢~

代码高亮

Butterfly支持五种高亮样式:

  • default
  • darker
  • pale night
  • light
  • ocean

配置 _config.yml

1
2
highlight_theme: light

复制

配置 _config.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Highlight theme
# ---------------
highlight_theme: light
highlight_copy: true #代碼複製按鈕
highlight_lang: true #代碼語言顯示
highlight_shrink: false #代碼框不展開,需點擊 '>' 打開

# copy setting
# 是否禁止複製(如果禁止,highlight_copy的功能將無效)
# copyright 複製的内容後面加上版權信息
copy:
enable: true # true 開啓 / false 禁止
copyright: true

换行

在默认情况下,配置中是不开启换行功能的,如果不希望在代码中有横向滚动条,可以开启这个功能。
配置 _config.yml

1
2
3
4
5
6
7
code_word_wrap: true
highlight:
enable: true
line_number: false
auto_detect: false
tab_replace:

社交图标

戳这里到对应的图标中心
配置 _config.yml

1
2
3
4
5
social:
fa fa-weixin: http://iblog.thatwang.com/qrcode_for_gh_706ce3f91494_258.jpg
fa fa-weibo: http://weibo.cn/wordpole9981
fa fa-qq: https://jq.qq.com/?_wv=1027&k=5E3IUHu

文章版权

配置 _config.yml

1
2
3
4
5
post_copyright:
enable: true
license: CC BY-NC-SA 4.0
license_url: https://creativecommons.org/licenses/by-nc-sa/4.0/

是否开启版权

1
2
3
copyright: false


文章打赏

配置 _config.yml

1
2
3
4
5
6
7
8
9
10
11
reward:
enable: true
QR_code:
- itemlist:
img: /img/wechat.jpg
text: 微信
- itemlist:
img: /img/alipay.jpg
text: 支付宝


头像

配置 _config.yml

1
2
3
avatar: https://xxxx/avatar.png


文章目录

配置 _config.yml

1
2
3
4
5
toc:
enable: true
number: true # 显示章节数字


相关文章

配置 _config.yml

1
2
3
4
5
related_post:
enable: true
limit: 6 # 显示推荐文章数量


博客年份

配置 _config.yml

1
2
3
since: 2018


页脚

配置 _config.yml

1
2
3
footer_custom_text: <a href="https://blog.thatwang.com/">Everybody's good at something.</a>


夜间模式

Apple都有这模式了,我们也不能输呀

配置 _config.yml

1
2
3
4
darkmode:
enable: true


阅读模式

阅读模式会去除文章以外的内容

配置 _config.yml

1
2
3
4
readmode:
enable: true


侧边栏设置

配置 _config.yml

1
2
3
4
5
6
7
8
9
10
11
aside:
position: right # left or right
card_author: true
card_announcement: true
card_recent_post: true
card_categories: true
card_tags: true
card_archives: true
card_webinfo: true


访问人数

配置 _config.yml

1
2
3
4
5
6
busuanzi:
site_uv: true
site_pv: true
page_pv: true


运行时间

配置 _config.yml

1
2
3
4
5
6
7
8
runtimeshow:
enable: true
start_date: 6/7/2018 00:00:00
##博客开通时间
# 格式: 月/日/年 时间
# 也可以写成 年/月/日 时间


相册

文章页面编辑以下markdown格式内容

1
2
3
4
5
{% gallery %}
markdown 圖片格式
{% endgallery %}


评论

戳这个leancloud服务

其实Hexo能支持很多评论系统,但是用下来,就leancloud这个最舒服,最方便

配置 _config.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
valine:
enable: true # if you want use valine,please set this value is true
appId: 配置中心查看 # leancloud application app id
appKey: key # leancloud application app key
notify: false # valine mail notify (true/false) https://github.com/xCss/Valine/wiki
verify: false # valine verify code (true/false)
pageSize: 10 # comment list page size
avatar: robohash # gravatar style https://valine.js.org/#/avatar
lang: zh-cn # i18n: zh-cn/en
placeholder: 来吧,造作吧,快活吧,肆无忌惮吧!(~ ̄ ̄)~ # valine comment input placeholder(like: Please leave your footprints )
guest_info: nick,mail,link #valine comment header info
bg: /img/comment_bg.png # valine background


img

注册登录

img

创建应用

img

获取key

此时就安装好了评论系统,就这么简单

img

评论

音乐

同样是使用leancloud服务

前面的注册逻辑与评论一样,接下来就是存储环节

[图片上传失败…(image-62aa11-1573183671188)]

加入单条音乐播放器的页面

1
2
3
{% aplayer "可以了" "陈奕迅" "https://xxx.xxx.com/92b3af330d2274b1fa55.mp3" "https://xxx.xxx.com/xx.png" "autoplay" %}


加入列表音乐播放器的页面

1
2
3
{% aplayerlist %}{"narrow": false,"autoplay": true,"showlrc": 3,"mode": "random","music": [{"title": "美好事物","author": "房东的猫","url": "http://xxx.xxx.com/945198c4909674765644.mp3","pic": "http://xxx.xxx.com/6e0e9e63cb0733f7ff12.png","lrc": ""},{"title": "尚好的青春","author": "云の泣","url": "http://xxx.xxx.com/5b42b829b8ae08ccabe0.mp3","pic": "http://xxx.xxx.com/889df742eca5261f2fc5.png","lrc": ""},{"title": "预谋邂逅","author": "阿肆","url": "http://xxx.xxx.com/1bd4f91441982710bcad.mp3","pic": "http://xxx.xxx.com/f72d61579f74d4ff9ce0.png","lrc": ""}]}{% endaplayerlist %}


即可

img

音乐播放器

分享

配置 _config.yml

1
2
3
4
5
sharejs:
enable: true
sites: wechat,weibo,qq


搜索

安装 hexo-generator-search,根据文档做对应配置

配置 _config.yml

1
2
3
4
5
6
7
local_search:
enable: true
labels:
input_placeholder: 试试看能找到啥宝藏吧!
hits_empty: "客官,本店还未提供该服务: ${query}" # if there are no result


自定义主题

配置 _config.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
theme_color:
enable: true
main: "#696969"
paginator: "#00c4b6"
button_hover: "#FF7242"
text_selection: "#00c4b6"
link_color: "#99a9bf"
meta_color: '#858585'
hr_color: "#A4D8FA"
read-mode-bg_color: '#FAF9DE'
inline-code-color: '#F47466'


打字效果

配置 _config.yml

1
2
3
4
activate_power_mode:
enable: true


动态彩带

配置 _config.yml

1
2
3
4
5
canvas_ribbon_piao:
enable: true
mobile: false # false 手机端不显示 true 手机端显示


背景线条

配置 _config.yml

1
2
3
4
5
6
7
8
9
canvas_nest:
enable: true
color: '0,0,255' #color of lines, default: '0,0,0'; RGB values: (R,G,B).(note: use ',' to separate.)
opacity: 0.7 # the opacity of line (0~1), default: 0.5.
zIndex: -1 # z-index property of the background, default: -1.
count: 99 # the number of lines, default: 99.
mobile: false # false 手机端不显示 true 手机端显示


鼠标点击效果

配置 _config.yml

1
2
3
4
5
6
7
8
fireworks:
enable: true

# 點擊出現愛心
click_heart:
enable: true


首页弹幕座右铭

配置 _config.yml

1
2
3
4
5
6
7
8
# 主頁subtitle
# 打字效果
# (如果有英文逗號' , ',請使用轉義字符 &#44;)
subtitle:
enable: true
sub:
- 努力不一定能成功&#44;但是永远不会后悔
- Hard work may not always result in success&#44;but it will never result in regret