记录通过Hexo搭建Github博客的过程, 记录、分享
部署环境:
1
2
3 ubuntu 14.04.3
node.js: v0.10.37
npm: 3.7.3
1. 安装node.js
1 | sudo apt-get install python-software-properties |
PS:由于网络原因可能导致无法下载安装脚本,请自行下载脚本后,执行sudo sh install.sh
安装。
2. 安装npm
1 | curl http://npmjs.org/install.sh | sudo sh |
3. 安装hexo
1 | five@master:~$ sudo npm install -g hexo |
4. hexo Step by Step
1 | mkdir hexo-project |
4.1 hexo init
1 | five@master:~/github/hexo-fivezh$ hexo init |
hexo init
: 新建文件夹(scaffolds, source, themes)和文件(_config.yml, package.json)
4.2 npm install
npm install
: 新建文件夹node_modules
4.3 hexo server
1 | five@master:~/github/hexo-fivezh$ hexo server |
这是可以通过浏览器访问http://0.0.0.0:4000/来查看初始效果。
4.5 Create new post
撰写文章前最好先停止hexo server,避免创建文章异常的问题。1
2five@master:~/github/hexo-fivezh$ hexo new "Hexo installation document"
INFO Created: ~/github/hexo-fivezh/source/_posts/Hexo-installation-document.md
编辑文档(source/_posts/xxxx.md)后,保存。
More info: Writing
4.6 Run server, 本地服务器预览
1 | $ hexo server |
4.7 Generate static files
生成文章静态页面(html, js, css)至publish目录,待发布、部署1
$ hexo generate
4.8 Deploy to remote sites 部署到远程服务器
1 | $ npm install hexo-deployer-git --save |
必须安装hexo-deployer-git, 新版本的hexo发布到git使用此部署。否则报错:ERROR Deployer not found: github
部署GitHub,需要修改_config.yml文件:1
2
3
4
5
6# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
type: git
resp: git@github.com:fivezh/fivezh.github.io.git
branch: master
#命令汇总1
2
3
4
5
6
7hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #将.deploy目录部署到GitHub
hexo help # 查看帮助
hexo version #查看Hexo的版本
简写命令:1
2
3
4hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy
快速复合命令:1
2
3$ hexo generate --deploy
$ hexo deploy --generate
上述两种表示作用相同
官网教程
由于hexo版本不一,命令及配置文件存在较大差异,结合官方文档安装、配置是最可靠的方式。
https://hexo.io/docs/#Install_Hexo
(网络原因无法打开,请自备梯子)
Install git
1 | sudo apt-get install git-core |
Install nvm + Node.js
1 | 安装nvm: |
Install Hexo
1 | npm install -g hexo-cli |
首页文章关闭全文显示,而显示”more”的设置:
theme/xxx/_config.yml中excerpt_link: more
, 在文章正文中摘要部分增加<!--more-->