加载中...
hexo教程
发表于:2022-03-03 | 分类: 编程 教程
字数统计: 1k | 阅读时长: 5分钟 | 阅读量:

快速、简洁且高效的博客框架

什么是 Hexo?

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

安装

1
$ npm install hexo-cli -g

建站

1
2
3
$ hexo init <folder>
$ cd <folder>
$ npm install

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

1
2
3
4
5
6
7
8
.
├── _config.yml
├── package.json
├── scaffolds
├── source
| ├── _drafts
| └── _posts
└── themes

配置

_config.yml
网站的 配置 信息,您可以在此配置大部分的参数。
package.json
应用程序的信息。EJS, Stylus 和 Markdown renderer 已默认安装,您可以自由移除。

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
package.json
{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "hexo generate",
"clean": "hexo clean",
"deploy": "hexo deploy",
"server": "hexo server"
},
"hexo": {
"version": "6.0.0"
},
"dependencies": {
"hexo": "^6.0.0",
"hexo-admin": "^2.3.0",
"hexo-deployer-git": "^3.0.0",
"hexo-deployer-heroku": "^0.1.2",
"hexo-filter-github-emojis": "^3.0.4",
"hexo-fs": "^3.1.0",
"hexo-generator-archive": "^1.0.0",
"hexo-generator-category": "^1.0.0",
"hexo-generator-index": "^2.0.0",
"hexo-generator-tag": "^1.0.0",
"hexo-log": "^3.0.0",
"hexo-offline": "^2.0.1",
"hexo-permalink-pinyin": "^1.1.0",
"hexo-renderer-ejs": "^2.0.0",
"hexo-renderer-kramed": "^0.1.4",
"hexo-renderer-pug": "^3.0.0",
"hexo-renderer-stylus": "^2.0.1",
"hexo-server": "^3.0.0",
"hexo-wordcount": "^6.0.1"
}
}

generate

1
2
3
$ hexo generate

$ hexo g

server

1
2
3
$ hexo server

$ hexo s

启动服务器。默认情况下,访问网址为: http://localhost:4000/。

deploy配置(_config.yml)

1
2
3
4
5
6
7
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repo: <repository url> #https://bitbucket.org/JohnSmith/johnsmith.bitbucket.io
branch: [branch]
message: [message]

部署

连接Github与本地
首先右键打开git bash,然后输入下面命令:

1
2
git config --global user.name "user"
git config --global user.email "user@you.com"

用户名和邮箱根据你注册github的信息自行修改。

然后生成密钥SSH key:

1
ssh-keygen -t rsa -C "user@you.com"

打开github,在头像下面点击settings,再点击SSH and GPG keys,新建一个SSH,名字随便。

git bash中输入

1
cat ~/.ssh/id_rsa.pub

将输出的内容复制到框中,点击确定保存。

输入ssh -T git@github.com,如果如下图所示,出现你的用户名和You’ve successfully字样,那就成功了。

1
ssh -T git@github.com

如果要更新以下不同的库,目前需要重复上面的步骤,各大神有好的方法可分享。
user1@you.com
user2@you.com
user3@you.com

安装 hexo-deployer-git。

1
$ npm install hexo-deployer-git --save

同步到github

1
2
3
$ hexo deploy

$ hexo d

坑(文件夹大小写问题,命令行删除 node_modules)

  • 大小写问题
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    cd .deploy_git
    git config core.ignorecase false #

    git rm -rf *
    git commit -m 'clean all file'
    git push

    cd ..
    hexo clean
    hexo deploy -generate
  • 删除node_modules
    1
    2
    npm install rimraf -g
    rimraf node_modules

主题&插件

  • Using hexo-theme-butterfly for hexo butterfly主题

    1
    git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
  • Using Kroki.io to generate diagrams for hexo kroki

    1
    npm install --save hexo-filter-kroki

hexo butterfly主题使用的坑

  • 启用hexo-filter-kroki,hexo-filter-mermaid-diagrams,hexo-filter-sequence插件之间有冲突,不能同时启用,只能使用其中一个。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
hexo clean
hexo g 结果不能编译
PS F:\Hexo> hexo g
INFO Validating config
INFO
===================================================================

##### # # ##### ##### ###### ##### ###### # # #
# # # # # # # # # # # # #
##### # # # # ##### # # ##### # #
# # # # # # # ##### # # #
# # # # # # # # # # # #
##### #### # # ###### # # # ###### #

4.1.0
===================================================================
INFO Start processing
PS F:\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
25
26
27
28
29
hexo clean
hexo g 结果正常
PS F:\Hexo> hexo g
INFO Validating config
INFO
===================================================================

##### # # ##### ##### ###### ##### ###### # # #
# # # # # # # # # # # # #
##### # # # # ##### # # ##### # #
# # # # # # # ##### # # #
# # # # # # # # # # # #
##### #### # # ###### # # # ###### #

4.1.0
===================================================================
INFO Start processing
INFO Files loaded in 2.69 s
INFO Generated: gallery/index.html
INFO Generated: gallery/1/index.html
INFO Generated: about/index.html
INFO Generated: gallery/2/index.html
INFO Generated: tags/index.html
INFO Generated: gallery/7/index.html
INFO Generated: categories/index.html
INFO Generated: gallery/3/index.html
INFO 38 files generated in 257 ms
INFO Generated manifests for 847 files. Total size: 335,214,206 bytes.
F:\Hexo>

图表示例

  • sequence
  • actdiag
  • nwdiag
  • mermaid
上一篇:
Kubernetes
本文目录
本文目录