teratail でも質問しましたが、こちらでも質問させていただきます。
前提・実現したいこと
セクション内にある記事で使われているカテゴリのリストを表示したい
(以下をご参照ください)
現状・問題点
静的サイトジェネレーターHUGOを触り始めた初心者です。
セクション内にある記事で使われているカテゴリだけのリストを表示する方法も探しています。
現状は、【All・カテゴリA・カテゴリB・カテゴリC・カテゴリD】になっていますが、
これを
section1のページ…【All・カテゴリA・カテゴリB】
section2のページ…【All・カテゴリC・カテゴリD】
にしたいということです。
※Allはsection○のトップページに飛ぶようにしています。
発生している問題・エラーメッセージ
実験中のためindex.md
だったり、_index.md
だったりバラバラです。
サイト名/
├ archetypes/
├ content/
│ ├ section1/
│ │ ├ categoryA/
│ │ │ ├ post
│ │ │ │ └ index.md
│ │ │ │
│ │ │ └ _index.md
│ │ │
│ │ ├ categoryB/
│ │ │ ├ _index.md
│ │ │ └ post2.md
│ │ │
│ │ ├ _index.md
│ │ └ post3.md
│ │
│ ├ section2/
│ │ ├ categoryC/
│ │ │ ├ index.md
│ │ │ └ post4.md
│ │ │
│ │ ├ categoryD/
│ │ │ ├ _index.md
│ │ │ └ post5.md
│ │ │
│ │ ├ _index.md
│ │ └ post6.md
├ layouts/
│ └ _default
│ ├ list.html
│ └ post.html
該当のソースコード
<!-- layouts/_default/list.html -->
{{ define "main" }}
{{ partial "page-title.html" . }}
<!-- blog(section1) -->
<section class="section">
<div class="container">
<ul>
{{ with .CurrentSection }}
<li><a href="{{ .RelPermalink }}">All</a></li>
{{- end }}
{{- range $taxonomyName, $taxonomy := .Site.Taxonomies }}
{{- range ($.Site.GetPage "taxonomyTerm" $taxonomyName).Pages }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{- end }}
{{- end }}
</ul>
<div class="row">
{{ range .Paginator.Pages }}
{{ .Render "post" }}
{{ end }}
</div>
{{ template "_internal/pagination.html" . }}
</div>
</section>
<!-- /blog(section1) -->
{{ end }}
<!-- layouts/_default/post.html -->
<div class="col-lg-4 col-sm-6 mb-4">
<article class="card shadow">
<img class="rounded card-img-top" src="{{.Params.Image | relURL}}" alt="{{.Title }}">
<div class="card-body">
<h4 class="card-title"><a class="text-dark" href="{{.RelPermalink}}">{{.Title }}</a>
</h4>
<p class="cars-text">{{.Summary}}…</p>
<a href="{{.RelPermalink}}" class="btn btn-xs btn-primary">Read More</a>
</div>
</article>
</div>
試したこと
<!-- layouts/_default/list.html -->
{{- range $taxonomyName, $taxonomy := .Site.Taxonomies }}
{{- range ($.Site.GetPage "taxonomyTerm" $taxonomyName).Pages }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{- end }}
{{- end }}
この部分が怪しいと思っています。
.Site.Taxonomies
はサイト全体で使用しているタクソノミーを取得しているという認識で合っていますか?
.Site.GetPage
でセクション内の記事を取得出来るということは分かったのですが、セクション内のタクソノミーだけをを取得する方法が分かりません。
補足情報(FW/ツールのバージョンなど)
こちらのテンプレートを使用しています。
Kross hugo
このデモサイトのポートフォリオページのカテゴリタブのようなものを、ブログのほうでも実現したいということです。