テーマしたい(/themes/)

1# hugo.toml
2theme = ["blowfish"]

themeキーで、テーマを変更できます。 テーマは Hugo Themes から選択できます。 ここでは、 blowfish テーマを例に説明します。

注釈

テーマは配列で指定できるので、複数のテーマを設定できます。 先頭のテーマが優先されます。

注意

themeキーを変更すれば、テーマを切り替えできます。 ただし、テーマごとにテンプレートの構造が異なるため、 レイアウトが崩れたり、ページが表示されなくなったりすることがあります。 テーマを切り替える場合は、テーマのドキュメントをよく読んで、必要に応じてテンプレートを修正してください。

テーマを追加したい

$ git submodule add https://github.com/nunocoracao/blowfish.git themes/blowfish

ほとんどのテーマはGitHubで公開されています。 git submodule addでサブモジュールとして追加します。 サブモジュールはthemes/テーマ名に追加します。

テーマを固定したい

$ cd themes/blowfish
$ git switch --detach v2.106.0
HEAD is now at a89d96e4 🐛 Pin fixed headers to the viewport top explicitly

$ cd ../..
$ git add themes/blowfish
$ git commit -m "pin blowfish theme to v2.106.0"

$ git submodule status
 a89d96e4dd63b0a1c1129d795ef4b56e491da1df themes/blowfish (v2.106.0)

サブモジュールの中に入ってgit switch --detachでタグやコミットを指定すると、テーマのバージョンを固定できます。 タグはブランチではないので、--detachオプションが必要です。 サブモジュールが指すコミットは親リポジトリ側にも記録する必要があるので、 themes/テーマ名をgit addしてコミットするところまでがワンセットです。

テーマを更新したい

$ git submodule update --remote themes/blowfish
Submodule path 'themes/blowfish': checked out 'ca56ac78a3806de12a3ef5f609c310919f6e7bda'

$ git submodule status
+ca56ac78a3806de12a3ef5f609c310919f6e7bda themes/blowfish (v3.2.0)

$ git add themes/blowfish
$ git commit -m "update blowfish theme"

--remoteオプションをつけてgit submodule updateを実行すると、 テーマのリモートリポジトリの最新コミット(既定ではデフォルトブランチのHEAD)まで更新されます。 git submodule statusの先頭の+は、親リポジトリが記録しているコミットとサブモジュールの実際のコミットがずれていることを示しています。 更新後は、固定のときと同じくgit add・git commitを忘れずに行います。

テーマを削除したい

$ git submodule deinit -f themes/blowfish
Cleared directory 'themes/blowfish'
Submodule 'themes/blowfish' (https://github.com/nunocoracao/blowfish.git) unregistered for path 'themes/blowfish'

$ git rm themes/blowfish
rm 'themes/blowfish'

$ git commit -m "remove blowfish theme"

git rmだけではサブモジュールの登録情報が.git/以下に残ってしまうため、 先にgit submodule deinitでサブモジュールの登録を解除してからgit rmします。

git submoduleの代わりに、Goのパッケージ管理の仕組みを使ってテーマを管理するモジュールしたいという方法もあります。