hexo 介绍

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

  2. 超快速度 Node.js 所带来的超快生成速度,让上百个页面在几秒内瞬间完成渲染。

  3. 支持 Markdown Hexo 支持 GitHub Flavored Markdown 的所有功能,甚至可以整合 Octopress 的大多数插件。

  4. 一键部署 只需一条指令即可部署到 GitHub Pages, Heroku 或其他平台。

  5. 插件和可扩展性 强大的 API 带来无限的可能,与数种模板引擎(EJS,Pug,Nunjucks)和工具(Babel,PostCSS,Less/Sass)轻易集成

  6. 374 主题 在众多美观、强大、可定制的主题中选择;使用任何兼容的模板引擎创建自己的主题。

hexo 开始使用

概述

安装 Hexo 只需几分钟时间,若您在安装过程中遇到问题或无法找到解决方式,请 提交问题,我们会尽力解决您的问题。

安装前提

安装 Git

安装 Git 博客网站内容需要用 git 来托管,有版本历史记录,内容也不会丢失,最后可以推送到 github 上长久存放的。

Windows:下载并安装 git.
Mac:使用 Homebrew, MacPorts 或者下载 安装程序。
Linux (Ubuntu, Debian):sudo apt-get install git-core
Linux (Fedora, Red Hat, CentOS):sudo yum install git-core

安装 Node.js

安装 Node.js, hexo 是用js写的,都是用npm来管理的

在我 本机 我的 node是安装在 /work/install/node-v14.15.4-linux-x64/ 位置的,
我的本机 ~/work 这个 work 目录是一个软连接,指向 /work 的, /work 挂载 的是我的第二块硬盘。
我的第一块硬盘是个固态盘,安装的系统 挂载在 根目录。扯远了。。。

我在 目录 下 放了多个node 的版本, 需要切换的时候 把那个 软连接 node 切换一下就行了

1
2
3
4
5
6
$ ll ~/work/install  
lrwxrwxrwx 1 mamh mamh 23 9月 24 12:23 node -> node-v14.15.4-linux-x64
drwxr-xr-x 6 mamh mamh 9 1月 4 2021 node-v14.15.4-linux-x64
drwxr-xr-x 6 mamh mamh 9 6月 2 03:16 node-v16.15.1-linux-x64
drwxr-xr-x 6 mamh mamh 9 9月 23 10:42 node-v16.17.1-linux-x64
drwxrwxr-x 6 mamh mamh 9 9月 11 2018 node-v8.12.0-linux-x64

安装 Hexo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

npm install hexo-cli -g


$ npm install hexo-cli -g
/work/install/node-v14.15.4-linux-x64/bin/hexo -> /work/install/node-v14.15.4-linux-x64/lib/node_modules/hexo-cli/bin/hexo
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/hexo-cli/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ hexo-cli@4.3.0
added 59 packages from 51 contributors in 27.28s


╭────────────────────────────────────────────────────────────────╮
│ │
│ New major version of npm available! 6.14.10 → 8.19.2 │
│ Changelog: https://github.com/npm/cli/releases/tag/v8.19.2 │
│ Run npm install -g npm to update! │
│ │
╰────────────────────────────────────────────────────────────────╯

$


查看 版本号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ hexo version  
hexo-cli: 4.3.0
os: linux 5.4.0-107-generic Ubuntu 18.04.2 LTS (Bionic Beaver)
node: 14.15.4
v8: 8.4.371.19-node.17
uv: 1.40.0
zlib: 1.2.11
brotli: 1.0.9
ares: 1.16.1
modules: 83
nghttp2: 1.41.0
napi: 7
llhttp: 2.1.3
openssl: 1.1.1i
cldr: 37.0
icu: 67.1
tz: 2020a
unicode: 13.0

查看帮助

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
$ hexo  
INFO Validating config
Usage: hexo <command>

Commands:
clean Remove generated files and cache.
config Get or set configurations.
deploy Deploy your website.
generate Generate static files.
help Get help on a command.
init Create a new Hexo folder.
list List the information of the site
migrate Migrate your site from other system to Hexo.
new Create a new post.
publish Moves a draft post from _drafts to _posts folder.
render Render files with renderer plugins.
server Start the server.
version Display version information.

Global Options:
--config Specify config file instead of using _config.yml
--cwd Specify the CWD
--debug Display all verbose messages in the terminal
--draft Display draft posts
--safe Disable all plugins and scripts
--silent Hide output on console

For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/


$ hexo --help
Usage: hexo <command>

Commands:
help Get help on a command.
init Create a new Hexo folder.
version Display version information.

Global Options:
--config Specify config file instead of using _config.yml
--cwd Specify the CWD
--debug Display all verbose messages in the terminal
--draft Display draft posts
--safe Disable all plugins and scripts
--silent Hide output on console

For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/


或者这样查看帮助
$ hexo help
Usage: hexo <command>

Commands:
help Get help on a command.
init Create a new Hexo folder.
version Display version information.

Global Options:
--config Specify config file instead of using _config.yml
--cwd Specify the CWD
--debug Display all verbose messages in the terminal
--draft Display draft posts
--safe Disable all plugins and scripts
--silent Hide output on console

For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/

hexo 建站

hexo init 初始化

这个就是 执行一个 初始化动作,类似 git init 这样的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$ hexo init <folder>  执行初始化动作,会下载一些东西的

$ hexo init hexo-blog # 命令后面 跟一个 名称,这个目录不存在就会在第一次新建出来的
INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git # 这里就说明 为啥需要 安装 git了。
INFO Install dependencies
warning hexo-renderer-stylus > stylus > css > source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated
warning Your current version of Yarn is out of date. The latest version is "1.22.19", while you're on "1.22.10".
INFO Start blogging with Hexo!


$ cd hexo-blog # 进入到刚刚初始化好的目录现,可以看到如下目录结构
$ ll
总用量 74K
-rw-rw-r-- 1 mamh mamh 0 10月 28 21:23 _config.landscape.yml
-rw-rw-r-- 1 mamh mamh 2.4K 10月 28 21:23 _config.yml
drwxrwxr-x 221 mamh mamh 222 10月 28 21:24 node_modules
-rw-rw-r-- 1 mamh mamh 615 10月 28 21:23 package.json
drwxrwxr-x 2 mamh mamh 5 10月 28 21:23 scaffolds
drwxrwxr-x 3 mamh mamh 3 10月 28 21:23 source
drwxrwxr-x 2 mamh mamh 3 10月 28 21:23 themes
-rw-rw-r-- 1 mamh mamh 70K 10月 28 21:24 yarn.lock


hexo init 完毕之后 最后也执行个 git init。 然后把目录现的所有文件都添加到git仓库里面

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
git init . 

git ci --allow-empty # 在添加文件之前现执行个 commit ,添加个标题 “init" 作为第一个git提交


git add . # 接下来再把当前目录现的所有文件 添加到git里面,

git ci # 做个第二个提交


$ git log # 最后的git log 看到会是如下的:
commit 1c4cdd23605a623ccfa82582d33c7dc7c60aa6fa (HEAD -> master)
Author: bright.ma <bright.ma@blackshark.com>
Date: Fri Oct 28 21:29:18 2022 +0800

add all init files

Signed-off-by: bright.ma <bright.ma@blackshark.com>

commit ab8ddf21d0e5ad32dce76be626c6b609f2fbb4ad
Author: bright.ma <bright.ma@blackshark.com>
Date: Fri Oct 28 21:29:08 2022 +0800

init

Signed-off-by: bright.ma <bright.ma@blackshark.com>


npm install 安装下载依赖

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

$ npm i
npm WARN deprecated source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 17 packages from 8 contributors, removed 13 packages, updated 225 packages and audited 243 packages in 29.962s

22 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities

$

目录结构介绍

新建完成后,指定文件夹的目录如下:

1
2
3
4
5
6
7
8
.
├── _config.yml 网站的 配置 信息,您可以在此配置大部分的参数。
├── package.json 这个就不说了 npm 管理的,该文件定义了项目所需的各种模块,以及配置信息(名称,版本,许可证等元数据)npm install 会根据这个配置文件自动下载所需要的模块
├── scaffolds 模版 文件夹。当您新建文章时,Hexo 会根据 scaffold 来建立文件。
├── source 资源文件夹是存放用户资源的地方。除 _posts 文件夹之外,开头命名为 _ (下划线)的文件 / 文件夹和隐藏的文件将会被忽略。Markdown 和 HTML 文件会被解析并放到 public 文件夹,而其他文件会被拷贝过去。
| ├── _drafts
| └── _posts
└── themes 主题 文件夹。Hexo 会根据主题来生成静态页面。

配置

命令

迁移

基本操作

写作

Front-matter

标签插件

资源文件夹

数据文件夹

服务器

生成器

部署

GitHub Pages

GitLab Pages

一键部署

自定义

永久链接

主题

模版

变量

辅助函数

国际化 (i18n)

代码高亮

插件

其他

问题解答

贡献