Please enable Javascript to view the contents

如何使用Hugo

 ·  ☕ 2 分鐘  ·  🐻 Cloud

如何使用Hugo

1. 環境需求

  • Hugo 是跨平台的

2. 安裝Homebrew (macOS or Linux)

  • Homebrew 包管理器可用於 Linux 和Windows Linux 子系統 (WSL)。在 Linux 或 WSL 上運行時,Homebrew 以前稱為 Linuxbrew。它可以安裝在您的主目錄中,在這種情況下它不使用sudo。Homebrew 不使用主機系統提供的任何庫,除非glibcgcc足夠新。Homebrew 可以為較舊的 Linux 發行版安裝自己當前版本的glibcgcc
1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Run these two commands in your terminal to add Homebrew to your PATH:

    1
    2
    
    echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/cloud/.profile
    eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
    

3. 安裝HOGO

1
brew install hugo

4. 建立網站

1
hugo new site myblog
  1. Download a theme into the same-named folder.
    Choose a theme from https://themes.gohugo.io/ or
    create your own with the “hugo new theme ” command.
  2. Perhaps you want to add some content. You can add single files
    with “hugo new /.”.
  3. Start the built-in live server via “hugo server”.

4.1 修改config.toml

(使用其他主題不用改)

1
2
3
baseURL = 'http://example.org/'
languageCode = 'zh-tw'
title = 'cloud 的筆記'
1
hugo config

4.2 add a themes

使用主題ZZO-docs

1
2
3
cd myblog
git init
git clone https://github.com/zzossig/hugo-theme-zzo.git themes/zzo

設定檔(範例)覆蓋到root目錄

1
cp -r themes/zzo/exampleSite/* .

config.toml修改

1
2
3
baseURL = "https://<your-username>.github.io/" #部署到 GitHub Pages
title = "Hugo Zzo Theme"
theme = "zzo"

編輯預設模板

1
vim archetypes/default.md

新增page1.md

1
hugo new posts/page1.md

建立靜態網站

1
hugo

本地運行 hugo 專案

1
hugo server

5. 部署到 GitHub Pages

建立Repository name <your-username>.github.io

建立靜態網站後出現public資料夾

1
2
3
4
cd public
git init
git add .
git commit -m "first commit"

push到github

1
2
3
git remote add origin git@github.com:<your-username>/<your-username>.github.io.git
git branch -M main
git push -u origin main

GitHub’s Repository->Settings->pages

Source 選擇branch main root 成功部署

6. 使用評論

https://utteranc.es/

A lightweight comments widget built on GitHub issues.

  1. 確保 repo 是公開的,否則您的讀者將無法查看問題/評論。
  2. 確保在 repo 上安裝了utterances 應用程序,否則用戶將無法發表評論。
  3. 如果您的 repo 是一個 fork,請導航到其設置選項卡並確認問題功能已打開。
分享

cloud
作者
Cloud
蔡逼八工程師