依赖环境准备
Node.js
安装
Hexo
是基于Node.js
安装的,因此需要先安装Node.js
, 安装地址为 Node.js
安装Node.js会包含环境变量及npm的安装, 安装完成后可以检查Node.js
是否安装成功
1 | node -v |
1 | npm -v |
Hexo
安装及初始化
Hexo是搭建个人网站的框架,安装方式如下
1 | ## 安装hexo |
Hexo
本地使用
Hexo
基本使用命令
1 | ## 新建一篇博客 |
运行完
hexo n my_first_site
后,可以在blog/source/_posts
文件夹下发现多了一个my_first_site.md
文件,此文件即我们编辑网页内容的主要源文件运行完
hexo s
之后,terminal会返回我们本地访问的网址,可以在上面查看预览样式1
2
3INFO Validating config
INFO Start processing
INFO Hexo is running at http://localhost:4000/ . Press Ctrl+C to stop.
Hexo
主题的选择
Next
主题
- 下载next主题
1
2## 下载next主题到blog/themes/下
git clone https://github.com/theme-next/hexo-theme-next themes/next - 修改Hexo配置文件使主题生效,将
blog/_config.yml
文件中的theme
设定成next
1
2
3
4# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next
完成之后重新运行Hexo g
以及Hexo s
即可预览验证主题是否生效
Hexo
的远程部署
github 创建自己用户名的个人仓库
ref: 从零开始,一步一步教你用 Github 快速搭建免费的个人主页
Hexo
和远程git仓库绑定
将blog/_config.yml
文件中的deploy
设定成指定的远程部署网页即可, 如下所示
1 | # Deployment |
Hexo
在远程网页上部署
在生成好静态网页之后,直接运行命令
1 | # 部署网页 |
这样最简单的网页部署就完成了,后面只需要修改blog/source/_posts/*.md
文件即可。
Hexo
高级配置
一般主题配置
1 | ## 修改作者, 文件名: (/_config.yml) |
自定义hexo new生成模板
hexo new (post/page/draft) $filename的模板,修改 /scaffolds/post.md
文件(page.md
和draft.md
文件同理)
1 | title: {{ title }} |
文章分类
分类展示
此处仅展示tags的设置, categories同理设定即可 1. 建立分类展示的静态页面
1 | hexo new page tags |
/source/tags/index.md
文件
设置页面类型, 直接在
index.md
文件中输入:1
2
3
4
5
6---
title: Tags
date: 2022-03-21 00:50:56
type: "tags"
comments: false
---修改菜单栏, 修改
themes/${theme_name}/_config.yml
文件,修改下列设置1
2
3
4menu:
home: /
archives: /archives
tags: /tags修改tags页面的字体大小, 修改文件
themes/${theme_name}/_config.yml
, 如下1
2
3
4
5
6
7
8# TagCloud settings for tags page.
tagcloud:
# All values below are same as default, change them by yourself.
min: 30 # Minimun font size in px
max: 50 # Maxium font size in px
start: "#ccc" # Start color (hex, rgba, hsla or color keywords)
end: "#111" # End color (hex, rgba, hsla or color keywords)
amount: 200 # Amount of tags, change it if you have more than 200 tags修改文章末尾的tag的图标, 修改文件
/themes/next/layout/_macro/post.swig
,替换为1
<a href="{{ url_for(tag.path) }}" rel="tag">{{ tag_indicate }} {{ tag.name }}</a>
1
<a href="{{ url_for(tag.path) }}" rel="tag"><i class="fa fa-tag"></i> {{ tag.name }}</a>
分类存储
通过修改配置文件blog/_config.yml
中的new_post_name
来让创建的文件按照时间分类,也可以按照(hexo new post --path filepath name
)来创建,示例如下
1 | permalink: :year/:month/:day/:title/ |
文章加密访问
简单方法
- 打开主题目录下layout/_partials/head.swig文件,在meta标签后面插入这样一段代码
1
2
3
4
5
6
7
8
9
10<script>
(function(){
if('{{ page.password }}'){
if (prompt('请输入文章密码') !== '{{ page.password }}'){
alert('密码错误!');
history.back();
}
}
})();
</script> - 在每篇文章md的开头添加
password: pwd
, 即可以激活### 安装插件方法 ref: hexo博客文章加密1
2
3
4
5
6---
title: Start with Hexo
date: 2022-03-19 00:06:40
tags: hexo
# password: mypwd
--- 安装插件
1
npm install --save hexo-blog-encrypt
在/_config.yml中输入响应配置
1
2
3
4
5
6
7
8
9# Security
encrypt: # hexo-blog-encrypt
silent: true
abstract: 这是一篇加密文章,需要密码才能继续阅读。
message: 当前文章暂不对外可见,请输入密码后查看!
tags:
- {name: private, password: mypwd}
wrong_pass_message: 抱歉,您输入的密码错误,请检查后重新输入。
wrong_hash_message: 抱歉, 当前文章不能被校验, 不过您还是可以看看解密后的内容解决解密后目录消失问题,找到文件
themes/next/layout/_macro/sidebar.swig
,编辑如下部分:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<aside class="sidebar">
<div class="sidebar-inner">
{%- set display_toc = page.toc.enable and display_toc %}
{%- if display_toc %}
## Start
{%- if (page.encrypt) %}
{%- set toc = toc(page.origin, { class: "nav", list_number: page.toc.number, max_depth: page.toc.max_depth }) %}
{%- else %}
{%- set toc = toc(page.content, { class: "nav", list_number: page.toc.number, max_depth: page.toc.max_depth }) %}
{%- endif %}
## End
## 同时删除 set toc这一句!!!
{%- set display_toc = toc.length > 1 and display_toc %}
{%- endif %}
插件安装
mermaid流程图
1 | ## 安装插件 |