快速搭建
Github Pages的配置
- 参考链接:
- 创建步骤
- 创建仓库(Create a repository),仓库命名必须是
username.github.io - 克隆仓库到本地(Clone the repository):
git clone [仓库地址] - 添加一个测试文件
index.html, 访问https://username.github.io就可以看到网站
- 创建仓库(Create a repository),仓库命名必须是
将Hexo部署到Github
在有node和git环境的情况下,安装Hexo
1npm install -g hexo-cli初始化Hexo
1234567cd username.github.io //进入本地目录git checkout -b hexo //创建一个名为hexo的分支//以下操作都是在hexo分支下进行的hexo init <folder> //folder可以任意命名,用于存放Hexo的相关目录cd <folder>npm installnpm install hexo-deployer-git --save //用于推送生成的文章到github仓库的部署Hexo
- 需要配置
_config.yml文件12345// 配置deploydeploy:type: gitrepo: <repository url> //就是仓库地址branch: master //一定要设置为master
- 需要配置
blog生成与发布
1hexo g -d //生成并发布再次打开访问
https://username.github.io。就可以看到一个blog了保存分支hexo
123git add .git commit -am "some message"git push origin hexo再次编辑或者新增文章后,只需要重复4,6步就可以了
原理
- 访问
https://username.github.io,会自动读取仓库username.github.io的master分支下的index.html文件- 仓库名为
username.github.io的仓库, 在setting>options>Github Pages>Source这个配置项是不可以更改的,只能为master(参考链接)。这就是为什么配置_config.yml时,branch只能为master
- 仓库名为
Hexo会把你写的Markdown文件编译成html文件。
开发目录如下:
123456- _config.html- package.json+ scaffolds- source+ _posts //所有的文章放在这里+ themes编译后的文件目录如下:
1234...+ css+ js- index.html
执行
hexo g -d命令会将编译后的文件push到master分支下,这样访问https://username.github.io时,就是一个通过Hexo生成的blog页面了
代码分支hexo
- 为什么要创建分支hexo?
- 因为使用
hexo g -d只会把编译后的文件push到master分支下。如果你有多台电脑,你不能在其他电脑上编辑文章。所以创建一个分支用来保存开发文件。
- 因为使用
- 参考链接
hexo分支下的文件操作
添加文章
1hexo new [layout] <title>更新修改到远程仓库的hexo分支
123git add .git commit -am "提交信息"git push origin hexo
- 参考链接: