配置发布到github
安装插件并修改配置
npm install hexo-deployer-git --save
配置_config.xml,修改如下内容
deploy:
type: git
repo: git@github.com:it-xusir/it-xusir.github.io.git
branch: master
repo替换成你的github新建的repo
branch默认master就可以
配置github仓库
进入官网 https://github.com/
点击右上角的 Sign up(注册),不是Sign in(登录)。
填写自己的邮箱、密码、用户名等信息,然后用邮箱验证即可完成。
创建仓库
点击右上角的+按钮,选择New repository,创建一个<用户名>.github.io的仓库
找不到创建入口的,访问:https://github.com/new
仓库的格式必须为:<用户名>.github.io
Description:为描述仓库(选填)
注意选择public仓库
勾选 Initialize this repository with a README 初始化一个 README.md 文件
点击 Creat repository 进行创建
配置git
执行命令
git config --global user.name "你的github用户名"
git config --global user.email "你的邮箱"
通过git config -l 检查是否配置成功,至此git安装及配置全部完成。
D:\it-xusir.github.io>git config -l
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=schannel
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.name=it-xusir
user.email=huiyangxu@hotmail.com
core.autocrlf=false
生成ssh公钥
ssh-keygen -t rsa -C "你的邮箱"
之后打开C盘下用户文件夹下的.ssh的文件夹,会看到 id_rsa.pub
用记事本打开上述图片中的公钥(id_rsa.pub),复制里面的内容,然后开始在github中配置ssh密钥。
进入github,点击右上角头像 选择settings
进入设置页后选择 SSH and GPG keys
title自己起个名,然后把密钥复制粘贴到key的框内,最后add sshkey
测试
D:\it-xusir.github.io>ssh -T git@github.com
Hi it-xusir! You've successfully authenticated, but GitHub does not provide shell access.
上传代码
还有一步配置别忘记了,把_config.xml里的url改成的你域名,如果你还没申请域名,就用github的博客地址。
url: https://itxusir.com/
然后
hexo clean
hexo generate
hexo deploy
每次你在本地修改完,再重复执行上面的命令,同步到github
配置域名解析
购买域名后,实名认证进入阿里云控制台,点云解析进去,找到你刚买的域名,
点进去添加两条解析记录:
1、cname记录添加,主机www,记录值就是你的github博客地址(我这里是it-xusir.github.io)
2、添加A记录, 主机记录@,记录值填github的IP地址(185.199.111.153、185.199.110.153、185.199.109.153、185.199.108.153)
打开博客/source目录,我的是D:\it-xusir.github.io\source,新建CNAME文件,注意没有后缀。然后在里面写上你的域名(例如:itxusir.com),保存。最后运行hexo g、hexo d上传到github。这样到最后当你在地址栏输入xxx.github.io时,才会自动跳转到你的域名。
打开你的github博客项目,点击settings,点击Pages,拉到下面Custom domain处,填上你自己的域名 ,保存。
最后勾选enforcehttps记录。让你的网站变成HTTPS