部署hexo
到github
上
1. 申请github
账号
- 进入
https://github.com/
申请,我这里申请的用户名是lmwings
- 建立个人仓库,仓库名为
lmwings.github.io
,这个是规则是固定的,一个账号只有一个github page
页面. 即<用户名>.github.io
2. 上传
把本地验证好的hexo
个人网站,上传到lmwings.github.io
仓库中
windows
安装好git
打开
Git Bash
,输入github
相关账号git config --global user.name "你的GitHub用户名" git config --global user.email "你的GitHub注册邮箱"
生成
ssh
密钥文件ssh-keygen -t rsa -C "你的GitHub注册邮箱"
直接一直回车即可,然后找到生成的
.ssh
文件夹中的id_rsa.pub
文件,把内容全部复制https://github.com/settings/keys
页面中新建new SSH Key
,标题随便起。验证密钥是否成功
在
git bash
中输入ssh git@github.com
Administrator@JIKXYRXHZ8CSKUY MINGW64 /e/work/hexo_blog $ ssh git@github.com PTY allocation request failed on channel 0 Hi lmwings! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed. Administrator@JIKXYRXHZ8CSKUY MINGW64 /e/work/hexo_blog
hexo
一些命令# 新建文章 hexo n 新建文章1 # 新建页面 hexo page categorys # 生成 hexo g # 启动服务预览 hexo s # 部署 hexo d # 清除缓存 hexo clean
修改本地
hexo
代码根目录下的_config.ymal
配置deploy: type: git repo: https://github.com/lmwings/lmwings.github.io.git branch: master
按照部署插件
npm install hexo-deployer-git --save
推送部署
hexo clean hexo g hexo d
访问验证
lmwings.github.io
部署到其他平台
部署到coding
由于github
是国外的,在国内访问较慢,所以我同时部署到gitee
和coding
上面。
步骤大部分和github
上面部署是一样的,下面做简单的记录
部署到
coding
首先,
https://coding.net/
申请账号这里会要求先创建团体,再创建用户,可以按自己随便起,里面可以修改。
然后,创建一个和自己的用户名一样的项目仓库, 注意: 启用README.md文件初始化项目 ,最好打钩,否则可能找不到
master分支
再,配置
ssh
公钥,这个步骤就是github部署
时候的第3步,电脑中生成的id_rsa.pub
文件即为公钥,为了能在多个代码托管平台工作,需要生成一个新的。这里输入的coding
就是生成是公钥文件名# Windows默认生成的路径 $ cd /c/Users/Administrator/.ssh # 生成公钥文件,后面邮箱是我注册的邮箱地址,输入文件名为 coding即会生成 coding.pud文件 $ ssh-keygen -t rsa -b 4096 -C 1321559220@qq.com Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): coding
然后把
coding.pub
的内容填写到https://lmwings.coding.net/user/account/setting/keys
测试一下是否设置正常
ssh -T git@e.coding.net
发现测试失败, 提示
git@git.coding.net: Permission denied (publickey).
这个要么就是
git
账号错误,要么就是ssh -T
命令输入错误了.配置
hexo
根目录下的_config.yml
deploy: type: git repo: github: https://github.com/lmwings/lmwings.github.io.git,master coding: https://e.coding.net/lmwings/lmwings.git,master
推送部署
hexo clean hexo g hexo d
需要在
condig.net
上需要实名认证后才允许使用
pages
功能,触发机制可以选择手动部署和自动部署构建与部署--静态网站--立即部署
访问上面的地址
https://722tv0.coding-pages.com/
部署到gitee
申请
gitee
账号https://gitee.com/
创建项目
项目名和用户名,还有范围地址中的最好是相同的,这个可以保证可以通过
<用户名>.gitee.io
进行访问,否则会多一级目录,我这里就填写lmwings
,然后创建到项目中,选择
服务--Gitee Pages
,部署分支选择master
即可,部署目录可以不用填,启用以后会有网站地址,我的地址为https://lmwings.gitee.io/blog
生成
ssh-key
公钥,这个和上面方法一样# Windows默认生成的路径 $ cd /c/Users/Administrator/.ssh # 生成公钥文件,后面邮箱是我注册的邮箱地址,输入文件名为 coding即会生成 coding.pud文件 $ ssh-keygen -t rsa -b 4096 -C 1321559220@qq.com Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): rsa_gitee
然后把
rsa_gitee.pub
填写到https://gitee.com/profile/sshkeys
(我自己使用一般直接设置账号的,不设置仓库的)测试一下是否正常
ssh -T git@gitee.com
部署更新后,到
gitee Pages
手动更新一下付费版本
gitee Pages Pro
,可以支持自定义域名,支持推送后自动部署,普通不行访问一下
https://lmwings.gitee.io/
部署到gitlab
申请
gitlab
账号https://gitlab.com/
创建项目, 名称规则同
github
, 即<用户名>.gitlab.io
生成
ssh-key
公钥,方法一样# Windows默认生成的路径 $ cd /c/Users/Administrator/.ssh $ ssh-keygen -t rsa -C 1321559220@qq.com Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): rsa_gitlab
然后把
rsa_gitlab.pub
填写到https://gitlab.com/profile/keys
测试一下是否正常
ssh -T git@gitlab.com
这个和其他的不一样,
没有显示的
gitlab pages
设置界面,主要是gitlab
有gitlab ci
, 如果项目中存在.gitlab-ci.yml
的文件,就会自动触发gitlab runner
来执行这个脚本,所以和其他发布不一样,这个仓库中需要上传的是本地的hexo源码
.gitlab-ci.yml
脚本编写可以参考(暂时还未来得及验证。)
https://hexo.io/zh-cn/docs/gitlab-pages
https://www.cnblogs.com/zhangnan35/p/10709252.html
一键部署
可以利用Traivs CI
等持续集成平台进行部署
参考https://hexo.io/zh-cn/docs/one-command-deployment