【Hugo】Shortcode内でGetPageを使うとタイムアウトする
前提
Hugo: v0.125.4
原因
ページAのSummary
を取得するにはページBのSummary
が必要だが、ページBのSummary
を取得するにはページAのSummary
が必要となってしまい、循環参照となりうまく取得できなくなっていた。
エラーについて
ページAとページBに以下のShortcode
で関連記事のリンクをお互いに作った際にタイムアウトする。
{{- with $path := .Get "path" -}}
{{- with site.GetPage . -}}
<div class="card">
<a href="{{ .RelPermalink }}" title="{{ .Title }}">{{ .LinkTitle | default .Title }}</a>
<div>
{{- .Summary -}}
</div>
</div>
{{- end -}}
{{- end -}}
エラーメッセージ
execute of template failed: template: _default/single.html:4:5: executing "_default/single.html" at <partial "head.html" .>: error calling partial: partial "head.html" timed out after 30s. This is most likely due to infinite recursion. If this is just a slow template, you can try to increase the 'timeout' config setting.
execute of template failed: template: _default/list.html:12:9: executing "main" at <partial "excerpt" .>: error calling partial: partial "excerpt" timed out after 30s. This is most likely due to infinite recursion. If this is just a slow template, you can try to increase the 'timeout' config setting.
まとめ
GetPage
を使用するShortcode
で、別記事へのリンクを作る際には、Content
を参照するものは避けた方がよさそう。
関連記事
-
【Hugo】別記事へのリンクを取得する前提 Hugo: v0.125.4 注意事項 この記事内で紹介しているShortcodeをそのまま使用すると、使用箇所によってはタイムアウトとなりうまく機能しない。 【Hu
-
【Hugo】目次(Table of Contents)を作る前提 Hugo: v0.125.4 TableOfContents 以下のメソッドを呼ぶだけで目次が作れる {{ .TableOfContents }} このページの場合、以下のhtmlが出力される <nav id="TableOfContents"> <ul> <li><a href="#前提"
-
【Hugo】MarkdownやソースコードをShortcodes内に記載する方法前提 Hugo: v0.125.4 対応内容 MarkdownをShortcode内に記載したときに、期待した結果が得られないことがあったので整理。 対応する方法としては、
-
【Hugo】Hugoの基本的な文法前提 Hugo: v0.125.4 変数 定義 {{ $foo := "foo" }} 代入 {{ $foo = "bar" }} テンプレート内での使用 <p>{{ $foo }}</p> 比較 Eq arg1 == arg2 {{ eq 1 1 }} # true {{ eq 1 2 }} # false {{ eq "foo" "foo" }} # true {{ eq "foo" "bar" }} # false 参考
-
【Hugo】Hugoの環境構築前提 環境: Windows Hugo: v0.125.4 インストール バイナリをダウンロードして配置 Githubからバイナリをダウンロード Releases latest ダウンロードしたファイルを解凍し、任意の