Hexo 入门

280 阅读1分钟

安装

在安装之前需要确保系统已经安装了:

运行下面的命令来检查是否安装:

# 检查 git 是否安装
$ git --version
# 检查 nodejs 是否安装
$ node --version

然后就可以安装 Hexo 的命令行工具了,运行下面的命令:

$ npm i -g hexo-cli

配置

安装成功以后运行下面的命令创建工作目录:

$ hexo init <FLODER NAME> && cd <FOLDER NAME>

安装依赖包:

$ npm i

这里我们拿 Next theme 做个例子。

安装 Next theme:

$ git clone https://github.com/theme-next/hexo-theme-next themes/next

然后在 _config.yml 中更改属性 theme

theme: next

Next 主题配置:

  • 创建 source/_data/next.yml 文件。
  • themes/next 目录下有个默认的配置文件 _config.yml,可以根据自己的需求从 _config.yml 选择需要的配置复制到 source/_data/next.yml 中。
  • Next 文档 中有非常详细的配置介绍。

工作流程

创建新的 post:

$ hexo new post <file name>

创建新的 draft:

$ hexo new draft <file name>

从 draft 发布新的 post:

$ hexo publish <file name>

运行 hexo server

$ hexo server -d

-d--draft 的简写,默认是不渲染 draft 文章的。

发布到 Github

下载 hexo-deployer-git

$ npm i hexo-deployer-git

_config.yml 中添加 deploy 属性:

deploy:
  type: git
  repo: <repository url>
  branch: [branch]
  message: [message]

发布:

hexo deploy --generate