Hexo¶
Hexo is a fast, simple and powerful blog framework. You write posts in Markdown (or other languages) and Hexo generates static files with a beautiful theme in seconds.
先决条件¶
依赖
- Node.js
- Git
Install Git¶
Linux (Ubuntu, Debian): sudo apt-get install git-core
Linux (Fedora, Red Hat, CentOS): sudo yum install git-core -y
# MacOS 可以使用brew安装git
# Windows直接下载安装包安装
Install Node.js¶
The best way to install Node.js is with nvm.
cURL:
$ curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | sh
Wget:
$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | sh
Once nvm is installed, restart the terminal and run the following command to install Node.js.
$ nvm install stable
# 或者直接使用如下命令
sudo yum install npm -y
# Windows直接下载安装包安装
使用Hexo¶
查看帮助¶
# 执行命令 hexo help
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 new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #将.deploy目录部署到GitHub
hexo help #查看帮助
hexo version #查看Hexo的版本
快速开始¶
# 在当前目录创建blog目录, 并将其初始化为hexo 仓库
hexo init blog
cd blog
# hexo generate的简写, 会显示大量信息. 这个过程会生成大量博客相关的文件(css, js, html等)
hexo g
# 本地预览
hexo server
显示如下信息
INFO Start processing
INFO Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.
浏览器访问 http://localhost:4000/
以上就是Hexo使用默认主题,
在本地预览的情况,生成的内容在public
目录下,
该目录有整个静态站点需要的内容.
Hexo配置¶
配置文件¶
hexo仓库下 _config.yml
文件
修改主题¶
https://hexo.io/docs/themes.html
使用Next主题¶
作者github上有主题详细信息, 具体请看上述链接
在hexo初始化的blog仓库里面执行如下命令
git clone --branch v5.1.2 https://github.com/iissnan/hexo-theme-next themes/next
修改主题为next, 文件 _config.yml
theme: next
Maupassant主题——大道至简¶
$ git clone https://github.com/tufu9441/maupassant-hexo.git themes/maupassant
$ npm install hexo-renderer-jade --save
$ npm install hexo-renderer-sass --save
# 若安装报错,请使用淘宝NPM镜像进行安装
npm install hexo-renderer-sass --save 报错的话:
[root@hexo blog]# npm uninstall node-sass
[root@hexo blog]# npm install node-sass@latest
Deployment¶
https://hexo.io/docs/deployment.html
部署到GitHub Pages¶
- 注册GitHub账号
- 新建仓库, 命名为
username.github.io
, username为用户名 - 使用ssh方式(需要配置公钥), 或者https方式(部署的时候会提示输入用户名及密码)
安装部署插件¶
npm install hexo-deployer-git --save
修改设置¶
Edit settings.
deploy:
type: git
repo: <repository url>
branch: [branch]
message: [message]
Option | Description |
---|---|
repo | GitHub/Bitbucket/Coding/GitLab repositor
y
URL |
branch | Branch name. The deployer will detect the branch automatically if you are using GitHub or GitCafe. |
message | Customize commit message (默认消息为
Update Site: YYYY-MM-DD HH:mm:ss ,
内容为当前时间) |
部署¶
hexo clean
hexo g -d
# 或者
# hexo d -g