准备工作
- 安装git
- 创建github账号
- nodejs(包含npm)
创建github仓库
仓库的名称是username.github.io
其中username
是你的用户名http://test.github.io
例如我创建的仓库名称为test
,我就可以用http://test.github.io
配置sshkey
ssh-keygen -t rsa -C "邮件地址"
在用户目录下找到.ssh/id_rsa.pub
文件,将内容复制到github中
配置全局用户
$ git config --global user.name "xxxx"// 你的github用户名,非昵称
$ git config --global user.email "xxxx@xx.com"// 填写你的github注册邮箱
搭建hexo
- 执行
npm install -g hexo
- 在某个地方创建目录,例如我在/home目录下创建blog目录
- 执行
hexo init /home/blog
在blog目录下初始化hexo - 进入
bolg
目录 - 编辑
_config.yml
修改URL部分
...
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: https://test.github.io/
root: /home/blog/
permalink: :year/:month/:day/:title/
permalink_defaults:
...
上传的github
- 依然修改
_config.yml
文件,修改Deployment部分
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: git@github.com:xxxx/test.github.io.git
branch: master
注意:冒号后面要有空格,不然会出错
- 执行
hexo g
- 执行
hexo d
- 如果出现奇怪的错误可以执行
hexo clean
清理一下
常用命令
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #部署到GitHub
hexo help # 查看帮助
hexo version #查看Hexo的版本