Lazy loaded image
如何利用Github建立多個個人網站
字数 694阅读时长≈ 2 分钟
2024-6-28
2024-6-28

簡介

GitHub Pages 是一項由 GitHub 提供的免費靜態網站託管服務,允許你直接從 GitHub 儲存庫中發佈網站。這項服務適用於個人、項目和組織網站,不需要伺服器端的動態內容處理。
 

如何使用 GitHub Pages建立主頁

創建儲存庫
在任何頁面的右上角,選擇 +然後按一下「New repository」
notion image
 
輸入 username.github.io 作為儲存庫名稱。 將 username 替換為你的 GitHub 使用者名稱。 例如,如果使用者名為 octocat,則儲存庫名稱應為 octocat.github.io。
notion image
在儲存庫名稱下,按一下 「Settings」。
notion image
在側邊欄的「Code and automation」部分中,按一下「Pages」。
在「Build and deployment」的「Source」下,選擇「Deploy from a branch」。
在「Build and deployment」的「Branch」下,選擇你要發佈的branch及根目錄,通常是master及/root,然後再按Save,如下圖。
notion image
這時你就可以訪問你的主頁,網址是https://username.github.io

建立第二個個人網站

在前一章節說明如何創建以https://username.github.io為你的個人主頁。
然而若想再創建你的第二個或是多個個人網站,則可依照以下步驟創建。
 
創建新的repository,在此以my-second-web-site為名。
然後在Settings找到pages
💡
在2024-6-30以後,Github把Build and deployment→Source改成必須使用GitHub Actions。因此以下將修改成用GitHub Actions來說明
在Build and deployment的Source選擇GitHub Actions
然後下方就會出現一些預設的workflow,在此以最簡單的方式建置,選擇Static HTML,按Configure
notion image
接下來會自動產生my-second-web-set/.github/workflows/static.yml
若沒有什麼特別設定,可以直接按右上角的Commit changes…
notion image
再按一次Commit changes
notion image
接下來在你的根目錄創建你的主頁,按右上角的…→Create new file
建立名為index.html的檔案。注意,是根目錄喔!
index.html的內容如下

plain

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <h1>Hello World</h1> </body> </html>
Plain text
回到<>Code主頁,按右邊的About的右邊的齒輪
 
notion image
勾選Use your GitHub Pages website,上方就會出現你的網址。
然後按Save changes
notion image
這時候,about面頁就會出現這個repository的網址
notion image
點擊網址就可以看到你剛剛創建的網頁 Hello World
notion image
以上利用這個方法就可以建立多個個人網站。方便展示作品。
 

參考

GitHub DocsGitHub DocsGitHub Pages 文档 - GitHub 文档
上一篇
如何用Tree列出資料夾結構包含子資料夾及檔案
下一篇
Java Method Reference

评论
Loading...