Hexo + GitHub 构建博客

1. 下载安装 Node

Node官网,一步步安装即可

2. 安装 Git

3. 申请 GitHub(用户名为 username ),配置 SSH Keys

创建仓库,名字固定:username.github.io

4. 安装 HEXO

打开Git Bash, 执行

1
sudo npm install -g hexo

如果不行,执行

1
npm install -g cnpm --registry=https://registry.npm.taobao.org

然后安装,执行

1
npm install hexo -g

5. 创建一个文件夹 blog ,在文件夹内 Shift + 右键打开命令窗口

执行

1
hexo init

再执行

1
hexo generate

(hexo g 也可以)

6. 启动 HEXO

执行

1
hexo server

浏览器输入 http://localhost:4000 即可打开

7. 修改 blog 下 _config.yml

最下方修改为

1
2
3
4
5
type: git
repository: https://github.com/username/username.github.io
branch: master

-其他配置自主修改

然后

执行

1
npm install hexo-deployer-git --save

执行

1
hexo deploy

现在查看 github 仓库,你会发现已经有很多文件了
在浏览器打开 https://username.github.io/ 即可访问

8. 常用命令

部署

1
2
3
hexo clean
hexo generate
hexo deploy

其他

1
2
3
4
5
6
7
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的版本

case:创建一片博文

1
2
3
4
5
1. hexo new "title"
2. \blog\source\_posts下会生成title.md文件,用MD编辑器打开,编写内容
3. hexo generate
4. hexo deploy
5. 完成,重新访问blog即可看到刚才编辑的文章
Hexo修改主题
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×