bernie6401
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 如何使用Hugo+Github架設網站 參考資料: [為了 SEO!我離開了 Medium,改在 GitHub 上自架個人網站](https://kucw.io/blog/2021/1/from-medium-to-github/) ## 註冊Github Account & Create Github Page 參考資料: [使用 GitHub Pages 架設個人網站](https://hackmd.io/@flagmaker/BkvQphP65) ## (Optional) 參考資料: [Github Pages 自訂網域教學](https://medium.com/zrealm-ios-dev/github-pages-%E8%87%AA%E8%A8%82%E7%B6%B2%E5%9F%9F%E6%95%99%E5%AD%B8-483af5d93297) ## Hugo Step 參考資料: [使用 Hugo 在 github 部署個人網站](https://sean22492249.medium.com/%E4%BD%BF%E7%94%A8-hugo-%E5%9C%A8-github-%E9%83%A8%E7%BD%B2%E5%80%8B%E4%BA%BA%E7%B6%B2%E7%AB%99-5b2ff19f8b6) ### 安裝Hugo(latest version) 1. 在[Github Release](https://github.com/gohugoio/hugo/releases)可以找到符合自己需求的版本,目前我是選`0.145.0_windows_amd64` 2. 解壓縮到`C:\hugo\bin` 3. 設定環境變數,設定完後測試 ```bash $ hugo version hugo v0.145.0-666444f0a52132f9fec9f71cf25b441cc6a4f355 windows/amd64 BuildDate=2025-02-26T15:41:25Z VendorInfo=gohugoio ``` ### Deploy Website on Local 1. Create New Site ```bash $ hugo new site demo Congratulations! Your new Hugo site was created in D:\Life\Website\demo. Just a few more steps... 1. Change the current directory to D:\Life\Website\demo. 2. Create or install a theme: - Create a new theme with the command "hugo new theme <THEMENAME>" - Or, install a theme from https://themes.gohugo.io/ 3. Edit hugo.toml, setting the "theme" property to the theme name. 4. Create new content with the command "hugo new content <SECTIONNAME>\<FILENAME>.<FORMAT>". 5. Start the embedded web server with the command "hugo server --buildDrafts". See documentation at https://gohugo.io/. ``` 2. 選擇Hugo Theme並且更新toml File 到Hugo的[Official Demo Theme](https://themes.gohugo.io/)看哪一個theme適合自己,假設我選擇relearn這個theme,就點選Download ```bash $ cd ./demo $ git submodule add https://github.com/McShelby/hugo-theme-relearn.git themes/relearn # 因為我是用relearn這個theme所以URL和folder name是customize # 也可以直接下載zip file,不過下面在設定toml file有一個地方要修改 $ echo theme = 'relearn'>> hugo.toml # For CMD $ echo "theme = 'relearn'" >> hugo.toml # For linux ``` 這個toml檔案就是一個config file,所以描述網站的最基本資訊 3. 新增一個測試的檔案 ```bash $ hugo new posts/hello.md $ cat ./content/posts/hello.md +++ date = '2025-04-02T19:15:29+08:00' draft = true title = 'Hello' +++ ``` hugo會在`./demo/content/posts`的地方新增一個hello.md這個檔案,並且把draft property改成false,最後deploy之後才會顯示 4. Deploy Local Server ```bash $ hugo server Watching for changes in D:\Life\Website\demo\{archetypes,assets,content,data,i18n,layouts,static,themes} Watching for config changes in D:\Life\Website\demo\hugo.toml, D:\Life\Website\demo\themes\relearn\hugo.toml Start building sites … hugo v0.145.0-666444f0a52132f9fec9f71cf25b441cc6a4f355 windows/amd64 BuildDate=2025-02-26T15:41:25Z VendorInfo=gohugoio | EN -------------------+----- Pages | 11 Paginator pages | 0 Non-page files | 0 Static files | 0 Processed images | 0 Aliases | 0 Cleaned | 0 Built in 163 ms Environment: "development" Serving pages from disk Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender Web Server is available at http://localhost:1313/ (bind address 127.0.0.1) Press Ctrl+C to stop ``` ![圖片](https://hackmd.io/_uploads/SkoITccp1e.png) 現在Local的deployment已經完成,剩下的就是deploy到Github Page ## 利用Github Action Deploy Hugo 1. 如果沒有碰過github action的人可能要先熟悉一下,這東西就是github的自動化流程,網路上有很多種action script,應該大同小異,我是用[peaceiris/actions-gh-pages](https://github.com/peaceiris/actions-gh-pages#getting-started) ```bash $ mkdir .github/workflows && touch .github/workflows/gh-pages.yml ``` ```yaml= name: GitHub Pages on: push: branches: - main # Set a branch name to trigger deployment pull_request: jobs: deploy: runs-on: ubuntu-22.04 permissions: contents: write concurrency: group: ${{ github.workflow }}-${{ github.ref }} steps: - uses: actions/checkout@v3 with: submodules: true # Fetch Hugo themes (true OR recursive) fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod - name: Setup Hugo uses: peaceiris/actions-hugo@v2 with: hugo-version: '0.145.0' - name: Build run: hugo --minify working-directory: ./demo - name: Deploy uses: peaceiris/actions-gh-pages@v3 # If you're changing the branch from main, # also change the `main` in `refs/heads/main` # below accordingly. if: github.ref == 'refs/heads/main' with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./demo/public ``` * on的意思是當main這個branches出現push的操作時,就要觸發這個workflow,也就是設定觸發條件的意思 * jobs就是說明要做的事情,具體要看jobs.deploy.steps的內容 * 因為有使用到別人的themes,並且如果是使用submodule的方式加入到git的話,submodules這個property就要設定true,但如果是直接下載的話就要設定成false * 因為我是使用`peaceiris`的workflow script所以uses就不用改,但hugo version就要改成latest的版本,不然會不過,像我的就是0.145.0 * Build minify的意思是透過hugo把指定資源進行最小化處理 * Deploy就是使用`peaceiris/actions-gh-pages@v3`這個版本的script,進行deploy,不用管具體在幹麻,需要注意的是,publish_dir是在`./demo/public`,因為hugo會把我寫的所有文章rendering之後放到./demo/public這個folder,所以我設定一個條件,如果main這個branch有變化,就把./demo/public這個folder中的所有內容,透過script更新到gh-pages 2. 設定Github的一些東西 到自己設定的website repo首頁`https://github.com/<username>/<username>.github.io`,會看到上面有Actions和Setting兩個subpage ![圖片](https://hackmd.io/_uploads/SJjgXj5pyx.png) 先到Setting > Pages ![圖片](https://hackmd.io/_uploads/HJZ4Xicpkg.png) 選擇Build and deployment中的選項為==GitHub Actions==,這個的意思是,因為Github在deploy類似Hugo這樣的靜態網頁框架時,如果選擇`Deploy from a branch`,那預設就會deploy Jekyll這個框架而不是Hugo導致deployment會失敗 如果在VScode的`GitHub Actions` Extension發現有另外一個workflow叫做`pages build deployment`那大機率就是這個地方沒有設定好,可以參考[禁用Github pages build deployment](https://blog.361way.com/2023/10/pages-build-deployment.html) 3. Push to repo ```bash $ git add . $ git commit -m "Init Website" $ git push ``` 丟上去到repo的時候可以透過vscode的`GitHub Actions`這個Extension查看有沒有deploy成功 ![圖片](https://hackmd.io/_uploads/rJNFHs5a1x.png) 有時候會出現像這樣deploy失敗的狀況,可以利用旁邊的View step logs查看具體哪邊出問題 4. (最重要的地方)更改Source變成Deploy from a branch,並且把Branch改成如下圖 ![圖片](https://hackmd.io/_uploads/BywW0hcaJe.png) 這邊的邏輯是: 1. 從 master (或 main) 分支的 Hugo 原始碼建置 (`hugo --minify`) 2. 將建置結果 (./demo/public/) 部署到 `gh-pages` 分支 3. GitHub Pages再從`gh-pages` branch提供網站 之後Source就不需要再改回`GitHub Actions`了 5. 如果之後要跟新文章,就直接像一般的git push那樣固定的add->commit->push這樣的流程就可以了,GitHub Actions會自己把東西deploy到public pages

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully