什么是Hexo?
Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。
NexT 是一款简洁优雅且易于使用的主题。
在 Hexo 中有两份主要的配置文件,其名称都是 _config.yml。 其中,一份位于站点根目录下,主要包含 Hexo 本身的配置;另一份位于主题目录下,这份配置由主题作者提供,主要用于配置主题相关的选项。
为了描述方便,在以下说明中,将前者称为 站点配置文件, 后者称为 主题配置文件。
安装
安装前提
安装 Hexo
1 | npm install -g hexo-cli |
建站
安装 Hexo 完成后,请执行下列命令,Hexo 将会在指定文件夹中新建所需要的文件。
1 | hexo init <folder> |
新建完成后,指定文件夹的目录如下:
1 | . |
配置
修改 站点配置文件。
网站
参数 | 描述 |
---|---|
title | xuchengpeng |
subtitle | Valar Morghulis. Valar Dohaeris. |
description | Valar Morghulis. Valar Dohaeris. |
author | xuchengpeng |
language | zh-CN |
timezone | Asia/Shanghai |
网址
参数 | 描述 |
---|---|
url | http://xuchengpeng.com/ |
permalink | :year/:month/:day/:title/ |
安装 NexT 主题
下载主题
1 | git clone https://github.com/theme-next/hexo-theme-next themes/next |
启用主题
修改 站点配置文件,搜索 theme
字段。
1 | theme: next |
主题设定
选择 Scheme
修改 主题配置文件,搜索 scheme
字段。
1 | # Schemes |
设置头像
修改 主题配置文件,搜索 avatar
字段。
1 | avatar: /images/bio-photo.jpg |
favicon 设置
1 | # For example, you put your favicons into `hexo-site/source/images` directory. |
关键字设置
1 | # Set default keywords (Use a comma to separate) |
页脚设置
1 | footer: |
主题配置
添加标签页面
1 | cd your-hexo-site |
修改刚新建的页面,内容如下:
1 | — |
修改 主题配置文件,添加 tags
到 menu
中。
1 | menu: |
添加分类页面
1 | cd your-hexo-site |
修改刚新建的页面,内容如下:
1 | — |
修改 主题配置文件,添加 categories
到 menu
中。
1 | menu: |
添加留言页面
1 | cd your-hexo-site |
修改刚新建的页面,内容如下:
1 | — |
修改 主题配置文件,添加 guestbook
到 menu
中。
1 | menu: |
菜单设置
1 | menu_settings: |
社交链接
1 | social: |
友情链接
1 | links_icon: link |
站点 License
1 | creative_commons: by-nc-sa |
文章 License
1 | # Declare license on posts |
打赏
1 | # Reward |
文章目录设置
1 | # Table Of Contents in the Sidebar |
侧边栏设置
1 | sidebar: |
设置代码高亮主题
1 | highlight_theme: normal |
调整内容区域显示的宽度
修改 主题配置文件:
1 | custom_file_path: |
在 variables.styl
文件中填入以下内容:
1 | // 修改成你期望的宽度 |
Pisces 和 Gemini 的修改方法为:
1 | $main-desktop = 85% |
标签设置
1 | # Note tag (bs-callout). |
第三方功能
设置页面文章的篇数
1 | npm install --save hexo-generator-index |
修改 站点配置文件,设定如下选项:
1 | index_generator: |
设置RSS
- 安装插件
1
npm install hexo-generator-feed --save
- 增加配置
修改 站点配置文件:1
2
3
4
5
6
7
8
9# 参数说明查看 README:https://github.com/hexojs/hexo-generator-feed
feed:
type: atom
path: atom.xml
# 文章数,0 为全部
limit: 0
hub:
# 是否包含文章内容
content: true
添加分享功能
下载插件
1
git clone https://github.com/theme-next/theme-next-needmoreshare2 source/lib/needsharebutton
修改 主题配置文件:
1
2
3
4
5
6needmoreshare2:
enable: true
postbottom:
enable: true
float:
enable: false
#### Gitalk评论支持
为NexT主题部署Gitalk评论插件
Valine评论系统
Valine 是一款基于Leancloud的快速、简洁且高效的无后端评论系统。
- 获取 App ID 和 App Key。
登录 LeadCloud,进入控制台后创建应用,进入应用,在设置
>应用Key
中获取 App ID 和 App Key。 - 在应用中配置自己的安全域名。
- 修改 主题配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13# Valine.
# You can get your appid and appkey from https://leancloud.cn
# more info please open https://valine.js.org
valine:
enable: true
appid: xxxxxxxxx # your leancloud application appid
appkey: xxxxxxxxxx # your leancloud application appkey
notify: false # mail notifier , https://github.com/xCss/Valine/wiki
verify: false # Verification code
placeholder: Leave your comments here... # comment box placeholder
avatar: wavatar # gravatar style
guest_info: nick,mail,link # custom comment header
pageSize: 10 # pagination size
文章阅读次数统计
- 获取 App ID 和 App Key。
登录 LeadCloud,进入控制台后创建应用,进入应用,在设置
>应用Key
中获取 App ID 和 App Key。 - 进入应用,在
存储
中创建名称为 Counter 的 Class,权限设置为 无限制。 - 修改 主题配置文件:
1
2
3
4
5
6# Show number of visitors to each article.
# You can visit https://leancloud.cn get AppID and AppKey.
leancloud_visitors:
enable: true
app_id: xxxxxxxx #<app_id>
app_key: xxxxxxxxxx #<app_key>
Fancybox
下载插件
1
git clone https://github.com/theme-next/theme-next-fancybox3 source/lib/fancybox
修改 主题配置文件:
1
fancybox: true
设置背景动画
下载插件
1
git clone https://github.com/theme-next/theme-next-canvas-nest source/lib/canvas-nest
修改 主题配置文件:
1
canvas_nest: true
字数统计和阅读时长
安装插件
1
npm install hexo-symbols-count-time --save
修改 站点配置文件:
1
2
3
4
5symbols_count_time:
symbols: true
time: true
total_symbols: true
total_time: true修改 主题配置文件:
1
2
3
4
5
6symbols_count_time:
separated_meta: true
item_text_post: true
item_text_total: true
awl: 5
wpm: 200
顶部加载进度条
下载插件
1
git clone https://github.com/theme-next/theme-next-pace source/lib/pace
修改 主题配置文件:
1
2pace: true
pace_theme: pace-theme-flash
Local Search
- 安装插件
1
npm install hexo-generator-searchdb --save
- 增加配置
修改 站点配置文件,添加如下配置:1
2
3
4
5search:
path: search.xml
field: post
format: html
limit: 10000 - 启用本地搜索
1
2local_search:
enable: true
验证主题
启动本地站点,并开启调试模式,命令是 hexo server --debug
。
此时可以使用浏览器访问 http://localhost:4000 ,检查是否运行正确。
生成器
使用 Hexo 生成静态文件快速而且简单。
1 | hexo generate |
部署
1 | npm install hexo-deployer-git --save |
修改 站点配置文件。
1 | deploy: |
Hexo 提供了快速方便的一键部署功能,让您只需一条命令就能将网站部署到服务器上。
1 | hexo deploy |
写作
修改文章模板
编辑 scaffolds/post.md
文件:
1 | --- |
多图展示
1 | --- |
多图排版格式见 iissnan/hexo-theme-next#295,参考 theme/next/scripts/tags/group-pictures.js
文件定义。
Label 写作样式
1 | {% label default@label_default %} |
Tab 写作样式
1 | {% tabs test %} |
这是选项卡 1 呵呵哈哈哈哈哈哈哈哈呵呵哈哈哈哈哈哈哈哈呵呵哈哈哈哈哈哈哈哈呵呵哈哈哈哈哈哈哈哈呵呵哈哈哈哈哈哈哈哈呵呵哈哈哈哈哈哈哈哈……
这是选项卡 2
这是选项卡 3 哇,你找到我了!φ(≧ω≦*)♪~
Note 写作样式
1 | {% note default %} |
note default
note primary
note success
note info
note warning
note danger
Button 写作样式
1 | {% button https://www.baidu.com, 点击下载百度, download fa-lg fa-fw %} |
文字字体和颜色
1 | <font color=red size=6 face=“黑体”>字体颜色</font> |
文字背景色
1 | <table><tr><td bgcolor=cyan>背景颜色</td></tr></table> |
背景颜色 |