前提

Windows上(Not WSL/WSL2)の VSCode + pwsh で管理する。

参考

https://gohugo.io/getting-started/quick-start/

準備

前提アプリケーション

  • git for windows
  • go (1.17)

hugo ダウンロード & インストール

https://github.com/gohugoio/hugo/releases からzipをダウンロード。

zipファイルを展開して、hugo.exe をパスが通っているフォルダに格納する。 (もしくは適当なパスに保存後、パスを通す)

サイト作成

サイト作成するフォルダに移動して、下記コマンドを実行する。 example.net はサイトの区別のための名前であり、わかれば何でもよい。 この名前のフォルダが作成される。

hugo new site example.net

テーマの導入

ここから好きなテーマを見つける。 https://themes.gohugo.io/

今回は hello-friend を使ってみる。

cd example.net
git init
git clone https://github.com/panr/hugo-theme-hello-friend.git themes/hello-friend

config.toml に下記を追加。

theme = "hello-friend"

コンテンツの追加

下記コマンドで新しいコンテンツを追加する。

hugo new posts/my-first-post.md

以下のような内容のファイルが作成される。 タイトル、作成日付、ドラフトかどうかの設定が既定値として登録される。 タイトルはファイル名から持ってくるようだ。ハイフンはスペースに変換される。

---
title: "My First Post"
date: 2022-02-11T08:47:11+01:00
draft: true
---

表示確認

ローカルでサーバーを立てて http://localhost:1313 からブラウザで表示を確認することができる。 -D オプションで、draft:true のコンテンツを表示可能。

hugo server -D

Start building sites  
hugo v0.92.1-85E2E862+extended windows/amd64 BuildDate=2022-01-27T09:00:00Z VendorInfo=gohugoio

                   | EN  
-------------------+-----
  Pages            | 12
  Paginator pages  |  0
  Non-page files   |  0
  Static files     | 10
  Processed images |  0
  Aliases          |  2
  Sitemaps         |  1
  Cleaned          |  0  

Built in 277 ms
Watching for changes in C:\dev\sites\example.org\{archetypes,content,data,layouts,static,themes}
Watching for config changes in C:\dev\sites\example.org\config.toml
Environment: "development"
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at //localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop

静的サイトの生成

下記コマンドにて draft: true も含めて静的サイトを生成すると、public フォルダ以下にデータが作成される。

hugo -D