现今比较流行的静态网页框架有 Jeklly,Hexo 和 Hugo。
选择 Hexo
的原因是 Next 主题,主要是支持中文,不需要自己配置了。
安装
在安装之前需要确保系统已经安装了:
运行下面的命令来检查是否安装:
# 检查 git 是否安装
git --version
# 检查 node 是否安装
node --version
然后就可以安装 Hexo
的命令行工具了,运行下面的命令:
yarn global add hexo-cli
部署
安装成功以后运行下面的命令创建工作目录:
hexo init <folder name> && cd <folder name>
安装依赖包:
yarn
安装 Next 主题:
git submodule add https://github.com/theme-next/hexo-theme-next.git 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
:
yarn add hexo-deployer-git
在 _config.yml
中添加 deploy
属性:
deploy:
type: git
repo: <repository url>
branch: [branch]
message: [message]
发布:
hexo deploy --generate