LoginSignup
1
0

Hugo server で failed to extract shortcode: template for shortcode "xxxx" not found になるときの解決

Last updated at Posted at 2023-09-14

ローカルでHugoサーバーを起動できなくなったときの原因と解決方法です。

Hugo server 起動に失敗する

Hugo と Github Pages でブログを作っていて、

ローカルでHugoを起動するコマンド

$ hugo server

を実行して起動しようとすると、
以下のようなエラーが突然出るようになりました。

$ hugo server
Start building sites …
hugo v0.110.0-e32a493b7826d02763c3b79623952e625402b168+extended windows/amd64 BuildDate=2023-01-17T12:16:09Z VendorInfo=gohugoio   
Error: Error building site: "C:\Users\hugo\aiko-han.github.io\content\post\rich-content\index.md:38:1": failed to extract shortcode: template for shortcode "bilibili" not found
Built in 36 ms

エラー文で怒られている index.md ファイルを確認してみます。

## bilibili Shortcode

{{< bilibili av498363026 >}}

「bilibili と index.md ファイルに書いてるけど、そんな shortcode は無いよ!」と言われているようです。

上記のエラーは、"bilibili" ですが、"Gist" であったり、他の shortcode の指摘
で同じエラーが発生することもあります。

何で急に not found・・・:disappointed_relieved: となりますが
原因は単純でした。

原因

原因は、「git cloneする際に Hugo のテーマを管理している Git のサブモジュールの取得が出来ていなかったこと」が原因でした。

つまり、hugo のディレクトリ構成は下記のようになっていても、themes ディレクトリ内のサブモジュールテーマが空になってしまっていたのです。

├── archetypes
├── content
├── layouts
├── resources
├── static
└── themes

解決方法

以下のコマンドで、取得しそびれてしまった submoduleで管理しているリポジトリを取得してあげれば解決です👍

$ git submodule update --init --recursive

実行すると以下のようにサブモジュールを clone できます。

$ git submodule update --init --recursive
Submodule 'themes/hugo-theme-stack' (https://github.com/CaiJimmy/hugo-theme-stack.git) registered for path 'themes/hugo-theme-stack'
Cloning into 'C:/Users/a0i2k/hugo/chacha8.github.io/themes/hugo-theme-stack'...
Submodule path 'themes/hugo-theme-stack': checked out 'aae9cf67db8661e86996f8808baf4f71c472d911'

この後、もう一度 $ hugo serverを実行すると、無事に起動できました!

おわりに

Hugo の中のテーマを Git のサブモジュールを使って構成していると、また遭遇しやすそうなエラーだったので自分の備忘録として残しておきました。
参考になれば嬉しいです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0