HugoのEvenでトップページに複数のセクションの記事を並べる
かなりハマってしまったので、備忘録に。
以下のような構造になっているとき。
https://gyazo.com/b9985fb0067bb8f6458dd2a9f7c91a5d
以下のように、postの記事も、annouceの記事もトップページ表示させる。
https://gyazo.com/8d76b3d4d234a086a7d9f8d3b88cd09a
Evenのindex.htmlは以下のようになっている。
code:index.html
<section id="posts" class="posts">
{{/* (index .Site.Paginate) */}}
{{- $paginator := .Paginate (where (where .Site.RegularPages "Type" "post") ".Params.hiddenfromhomepage" "!=" true) }}
{{- range $paginator.Pages -}}
{{ .Render "summary" }}
{{ end -}}
</section>
.Site.RegularPages "Type" "post"の部分を何とかしたらいいことはわかる。
Site Variables | Hugo
Hugo をしばらく触ってなかったので、わかりやすくまとめ直した - ばうあーろぐ
where | Hugo
Hugo の カテゴリー(categories) を 階層化 する | のい太ろぐ
ポイントは二つ。まず、.Site.RegularPagesの指定を複数にすること。これは、直接は無理で、config.tomlでリストを宣言しておく。
code:config.toml
params
frontPageSections = "book","announce","post"
で、index.htmlを書き換える。
code:index.html
<section id="posts" class="posts">
{{/* (index .Site.Paginate) */}}
{{- $paginator := .Paginate (where (where site.RegularPages "Section" "in" site.Params.frontPageSections) ".Params.hiddenfromhomepage" "!=" true) }}
{{- range $paginator.Pages -}}
{{ .Render "summary" }}
{{ end -}}
</section>
inをつけてリスト引き受け体制にして、先ほど宣言した指定する。
これで、呼び出されはするのだが、Evenでは、summaryでレンダーされるので、そのセクション用のフォルダにsummary.htmlがないと描写されない。
postのもので構わないのでコピペしておく。
https://gyazo.com/3aec8f18f02b82f148e48daa790a84d5
これでOK。
Hugo