hexo配置

推荐网站(hexo的文档):https://hexo.io/zh-cn/docs/

安装前提

安装下列软件:

  • Node.js (Node.js 版本需不低于 10.13,建议使用 Node.js 12.0 及以上版本)

  • Git

修改npm源为淘宝源

1
2
3
4
5
6
#查看npm源
$ npm config get registry
#设置npm源
$ npm config set registry https://registry.npm.taobao.org/
# npm官方源 https://registry.npmjs.org
# npm淘宝源 https://registry.npm.taobao.org/

安装hexo

安装

1
$ npm install -g hexo-cli

安装 Hexo 完成后,请执行下列命令,Hexo 将会在指定文件夹中新建所需要的文件。

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
应用程序的信息。

scaffolds
模版文件夹。当新建文章时,Hexo会根据scaffold来建立文件。

source
资源文件夹是存放用户资源的地方。除 posts 文件夹之外,开头命名为 (下划线)的文件 / 文件夹和隐藏的文件将会被忽略。Markdown 和 HTML 文件会被解析并放到 public 文件夹,而其他文件会被拷贝过去。

themes
主题文件夹。Hexo会根据主题来生成静态页面。

hexo常用指令

init

1
$ hexo init [folder]

新建一个网站。如果没有设置 folder ,Hexo 默认在目前的文件夹建立网站。

new

1
$ hexo new [layout] <title>

新建一篇文章。如果没有设置layout的话,默认使用_config.yml中的default_layout参数代替。如果标题包含空格的话,请使用引号括起来。

1
$ hexo new "post title with whitespace"

generate

生成静态文件

1
2
#可简写为hexo g
$ hexo generate

server

1
2
#可简写为hexo s
$ hexo server

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

deploy

1
2
#可简写为hexo d
$ hexo deploy

部署网站。

clean

1
$ hexo clean

清除缓存文件 (db.json) 和已生成的静态文件 (public)。
在某些情况(尤其是更换主题后),如果发现对站点的更改无论如何也不生效,可能需要运行该命令

hexo部署

Hexo提供了快速方便的一键部署功能,只需一条命令就能将网站部署到服务器上。

1
$ hexo deploy

在开始之前,必须先在 _config.yml 中修改参数,一个正确的部署配置中至少要有 type 参数,例如:

1
2
deploy:
type: git

可同时使用多个deployer,Hexo会依照顺序执行每个deployer。

1
2
3
4
5
deploy:
- type: git
repo:
- type: heroku
repo:

hexo部署到gitee

配置gitee

准备工作

  • 安装软件:node.js和git
  • 注册gitee

配置
git bash here中输入以下命令进行配置

1
2
$ git config --globale user.name "gitee空间地址"   //gitee用户名
$ git config --globale user.email "xxx@qq.com" //你注册gitee的邮箱

gitee新建仓库
新建仓库
gitee新建仓库
新建仓库
开启Gitee Pages服务
giteePages服务
强制使用https

安装git

  1. 安装 hexo-deployer-git。
1
$ npm install hexo-deployer-git --save
  1. 修改配置(_config.yml)
1
2
3
4
5
deploy:
type: git
repo: <repository url> #https://gitee.com/ccchenji/ccchenji
branch: [branch]
message: [message]
参数 描述 默认
repo 库(Repository)地址
branch 分支名称 master
message 自定义提交信息
  1. 生成站点文件并推送至远程库。执行 hexo clean && hexo deploy。

hexo部署到阿里云oss

安装插件:hexo-deployer-aliyun

说明:
部署hexo到阿里云oss

地址:
hexo-deployer-aliyun

插件安装:
$ npm install hexo-deployer-aliyun --save

插件选项:
_config.yml中配置插件

1
2
3
4
5
6
deploy:
type: aliyun
bucket: <yourBucketName>
region: <yourOSSregion>
accessKeyId: <yourAccessKeyId>
accessKeySecret: <yourAccessKeySecret>

region查询

点击:region查询

如华东1:oss-cn-hangzhou

hexo 插件推荐

hexo-blog-encrypt

说明:
对hexo文章进行加密

使用:

将“ password”添加到您的文章信息头

1
2
3
4
5
---
title: Hello World
date: 2022-03-13 21:12:21
password: 123456
---