Migrate blog to Github(HTTPS) and add continuous integration

Reference

MARKSZのBlog

Continuous integration

Set Travis-CI account and Token

  1. Sign up Travis-CI and sync your Git-hub account:

Sign_up

  1. Choose your *github.io:

repo

  1. Set Token:

First step: check Settings

setting

Second step: find Developer settings

setting2

Third step: generate your token (you can type any name you like) and check ‘repo’:

setting3_1

setting3_2

Because the token just show once, you must record your token!! Otherwise, you’ll need to generate again.

  1. Add Environment Variable

We can store the generated token as GH_TOKEN which will help us write .travis.yml file later.

Environment Variable

Write config file

.travis.yml is the config file of Travis-CI. You need to generate one and push to the root of your Git-hub repository (*github.io).

Here’s the example of .travis.yml and you should change according to your own account:

language: node_js # 声明环境为node
node_js: stable

# Travis-CI Caching
cache:
  directories:
    - node_modules # 缓存node_modules文件夹

# S: Build Lifecycle
install:
  - npm install -g hexo-cli # 下载依赖

script:
  - hexo g

after_script: # 推送到github的部分
  - cd ./public
  - git init
  - git config user.name "zxdawn"
  - git config user.email "[email protected]"
  - git add .
  - git commit -m "Update docs"
  - git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" master:master # 通过之前存在Travis-CI里的token以及github仓库的地址推送到相应的master分支
# E: Build LifeCycle

branches:
  only:
    - master # 只对master分支构建

env: # 环境变量
 global:
   - GH_REF: github.com/zxdawn/zxdawn.github.io.git # 我的仓库地址

Add HTTPS to blog

I’ll explain how to add HTTPS to your blog, if you have your own domain name instead of *github.io.

You can add HTTPS easily and freely by Cloudflare

Use custom domain with GitHub Pages

You need to add your domain to GitHub according to GitHub tutorial.

  1. Set custom domain:

Custom domain

  1. Create A records that point your custom domain to GitHub IP:

DNS server

Sign up Cloudflare account

Manage DNS

Type A points to Git-hub IP. Tyoe CNAME points www subdomain to apex domain.

DNS

Click ‘Next’ and change NameServer of your DNS server according to Cloudflare guide.

NameServer

Turn on HTTPS

Turn on flexible SSL

SSL

Redirect traffic to HTTPS

If others visit my blog by http://dreambooker.site, how can I let them visit https://dreambooker.site directly?

We can use the function of Page Rules:

Page Rules

By the way, this method is the redult of communication between browser and server. We can use HSTS to make redirect safely and quickly. HSTS is under the menu of Crypto:

HSTS


Say something

Thank you

Your comment has been submitted and will be published once it has been approved.

Click here to see the pull request you generated.

OOPS!

Your comment has not been submitted. Please go back and try again. Thank You!

If this error persists, please open an issue by clicking here.