GitHub 建立專案首頁 project page

使用 Github Pages 功能可以免費地為專案建立首頁。
以下介紹直接將專案下 README.md 來作為專案首頁的方法。

先到你的專案的 repository 下建立 gh-pages 分支,
這個 gh-pages 分支就是擺放靜態網頁相關的分支,
我是放 github jekyll 模板支援的主題,所以只要放 README.md 和 _config.yml 就可以了

1
2
3
4
5
git checkout --orphan gh-pages # 建立一個沒有 parent 的 branch,並切換到該 branch 上
git rm -rf . # 刪除從原本分支複製到 gh-pages 分支的所有檔案
git add README.md _config.yml # 把要顯示在首頁的相關檔案 commit 進去
git commit
git push origin gh-pages

_config.yml 是個 jekyll 的全域的設定檔案,
可以設定網站的名字,網站的域名,網站的連結格式等等。
以下為 jekyll-theme-slate 的設定方式

_config.yml查看實際範例
1
theme: jekyll-theme-slate

每個用戶都會自動分配一個域名,
github 上的 repository 與域名對應的關係如下:
https://github.com/username/project
對應到
https://username.github.io/project

參考
https://docs.github.com/en/free-pro-team@latest/github/working-with-github-pages/creating-a-github-pages-site
建立自己的GitHub Project Pages
https://github.com/hoperyy/blog/issues/10

其它相關文章推薦
GitHub 建立靜態網頁 GitHub Pages
Github 更換 Github Pages 網頁主題