部署多个远程托管

由于github服务器在国外,相应速度慢,同时将代码托管在国内的Coding和国外的Github上,使用同一域名,提高相应速度

码云的Pages服务需要购买服务才能自定义域名,所以推荐使用Coding

Coding设置

Coding项目名

定义项目名为

<username>.coding.me

必须定义成上面格式,否则无法设置DNS解析

Coding Pages设置

参考:

手把手教你用Hexo+(Coding/GitHub)搭建个人博客及绑定私有域名

如何创建静态 Coding Pages?

将静态文件上传到Coding后,开启Pages服务,此时打开网站会出现文件无法解析的情况,需要进一步设置自定义域名

注意:Coding对于Pages部署次数有限制

静态 Pages 有部署次数限制,付费会员为每小时可以部署 30 次,非付费会员每小时可以部署 10 次

本地部署

参考:认证

如果在本地使用插件hexojs/hexo-deployer-git进行部署,那么修改工程_config.ymldeploy小节

...
url: https://www.zhujian.tech
...

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
    - type: git
    repo: 
        github: https://github.com/zjZSTU/zjzstu.github.com.git,master
        coding: git@git.dev.tencent.com:zjZSTU/zjZSTU.coding.me.git,master
...
  1. 设置url为自定义域名

  2. 使用HTTP协议传输代码到Github,使用SSH协议传输代码到Coding

格式如下:

deploy:
    type: git
        message: [message]
        repo:
            github: <repository url>,[branch]
            coding: <repository url>,[branch]

远程部署

参考:

Creating a personal access token for the command line

如果通过git上传代码到Github,在通过Travis Ci进行自动部署,那么需要设置传输协议为HTTP,同时加上个人令牌密码

具体参考[Travis CI]持续集成

工程_config.yml文件修改如下:

...
url: https://www.zhujian.tech
...

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
    - type: git
    repo: 
        github: https://github.com/zjZSTU/zjzstu.github.com.git,master
        coding: git@git.dev.tencent.com:zjZSTU/zjZSTU.coding.me.git,master
...

_travis.yml文件修改如下:

after_success:
    - sed -i'' "s~https://github.com/zjZSTU/zjzstu.github.com.git~https://${GITHUB_REPO_TOKEN}@github.com/zjZSTU/zjzstu.github.com.git~" _config.yml
    - sed -i'' "s~git@git.dev.tencent.com:zjZSTU/zjZSTU.coding.me.git~https://zjZSTU:${CODING_REPO_TOKEN}@git.coding.net/zjZSTU/zjZSTU.coding.me.git~" _config.yml
    - hexo deploy

Coding注意

个人访问令牌

Travis CI 自动部署hexo到GitHub/Coding

Coding仓库当前的HTTP链接为

https://git.dev.tencent.com/<user-name>/<repo-name>.git

需要进一步改成

https://git.coding.net/<user-name>/<repo-name>.git

否则无法使用,坑!!!