GitHub Pages

東挑西選搞了很久,最後決定用GitHub Pages + Hexo來架設Blog,所以就順手寫個文章介紹一下這兩個東西吧!

GitHub Pages 是由 GitHub 提供的靜態網頁代管服務,只要將網頁 Push 到指定的 Repository 下的 Branch 即可發佈到對應的網址。GitHub Pages 基本上分為兩種類型,User/Organization PagesProject Pages,兩者功能是一樣的,只是在使用方式及其對應的網址上有些差異。

User/Organization Pages

建立一個Repository名為<username>.github.io,然後Push網頁到這個Repository的master,成功後即可透過http(s)://<username>.github.io看到網頁了。

若是Organization Pages,username改為orgname

Project Pages

存放Project Pages網頁的路徑有三個地方可以選master, master裡的/docs目錄還有名為gh-pages的Branch。其中gh-pages會在建立之後,GitHub Pages 的設定會自動對到這個 Branch,但是如果是要指定到master或是在master裡的/docs目錄,那就要自己去改設定了。設定好存放網頁的路徑後,把網頁Push到指定的路徑,完成後即可透過http(s)://<username>.github.io/<projectname>看到網頁了。

網址跟檔案位置的對應表

網站類型 預設網址 網頁存放的位置
User Pages site username.github.io master
Organization Pages site orgname.github.io master
User Project Pages username.github.io/projectname master, gh-pages, 或是在master裡的/docs目錄
Organization Project Pages orgname.github.io/projectname master, gh-pages, 或是在master裡的/docs目錄

Using a custom domain

直接在Repository的設定裡修改,或是在存放網頁的目前裡,新增一個檔案CNAME,然後把你的網域名稱寫在裡面,Push 上去就可以了。

例如github_pages這個 Repository 底下的gh-pages裡有設定一個CNAME內容是pages.gclin.org,即可以
https://gclin.github.io/github_pages 轉到 http://pages.gclin.org/

記得要先把 pages.gclin.org 指到 gclin.github.io

Creating a custom 404 page

Creating a custom 404 page for your GitHub Pages site

使用限制

  • GitHub Pages 的 Repository 建議保持在1GB以內
  • 發佈的 GitHub Pages 網站不可超過1GB
  • 每月流量限制100GB
  • 每小時最多進行10次建置

GitHub 對 Repository 的用量,除了單一檔不可大於100MB(從Browser上傳的話是25MB)之外,並沒有配額限制,只會在用量大於1GB時,GitHub 會寄信提醒。

Demo

這邊用的 Repository 是這個 https://github.com/gclin/github_pages/

把Source設定為 master branch

把Source設定為 master branch /docs folder

把 Source 設定為 gh-pages branch

目前這個 Project pages 是套用這個設定,可以透過下面這兩個網址查看