Hextraでtagsが表示されずハマった話
Hextraでtagsが表示されずハマった話
2025年 5月 20日
Hextraのtagsページに記事が表示されない問題を解決したので、その備忘録
Tagsページに記事が表示されない!
本サイトはHUGOというフレームワークとHextraというtheme(テーマ)で作成している。
デモサイトでは"/tags/Example"にそのタグに該当する記事の一覧が表示されるはずなんだけど、自分の環境では表示されなかった。
環境
- HUGO v0.146.5
- Hextra v0.9.7
改善方法
該当するhtmlファイルを書き換えた。
具体的手順は下記の通り
- term.htmlのリネームと書換え
- taxonomy.htmlの書き換え
試行錯誤の中で解決したので、なぜ解決したのかは忘れましたハナホジ
term.htmlのリネームと書換え
“your_project/theme/layouts/“にある"term.html"を"terms.html"にリネームし、次のように書き換える。
{{ define "main" }}
<div class='hx:mx-auto hx:flex {{ partial "utils/page-width" . }}'>
{{ partial "sidebar.html" (dict "context" . "disableSidebar" true "displayPlaceholder" true) }}
{{ partial "toc.html" (dict "Params" (dict "toc" false)) }}
<article class="hx:w-full hx:break-words hx:flex hx:min-h-[calc(100vh-var(--navbar-height))] hx:min-w-0 hx:justify-center hx:pb-8 hx:pr-[calc(env(safe-area-inset-right)-1.5rem)]">
<main class="hx:w-full hx:min-w-0 hx:max-w-6xl hx:px-6 hx:pt-4 hx:md:px-12">
<br class="hx:mt-1.5 hx:text-sm" />
{{ if .Title }}<h1 class="hx:text-center hx:mt-2 hx:text-4xl hx:font-bold hx:tracking-tight hx:text-slate-900 hx:dark:text-slate-100">{{ .Title }}</h1>{{ end }}
<div class="hx:mb-16"></div>
<div class="content">
{{ .Content }}
</div>
<div class="hx:grid hx:grid-cols-1 hx:md:grid-cols-2 hx:lg:grid-cols-3 hx:xl:grid-cols-4 hx:gap-4">
{{ range .Data.Terms }}
<div class="hx:w-full">
<a
href="{{ .Page.RelPermalink }}"
title="{{ .Page.LinkTitle }}"
class="hx:font-medium hx:hover:text-primary-600"
>
{{- .Page.LinkTitle -}}
<span class="hx:text-sm hx:text-gray-500"> {{ .Count }}</span>
</a>
</div>
{{ end }}
</div>
</main>
</article>
</div>
{{ end }}
taxonomy.htmlの書き換え
“your_project/theme/layouts/“にある"taxonomy.html"を、次のように書き換える。
{{ define "main" }}
<div class='hx:mx-auto hx:flex {{ partial "utils/page-width" . }}'>
{{ partial "sidebar.html" (dict "context" . "disableSidebar" true "displayPlaceholder" true) }}
{{ partial "toc.html" (dict "Params" (dict "toc" false)) }}
<article class="hx:w-full hx:break-words hx:flex hx:min-h-[calc(100vh-var(--navbar-height))] hx:min-w-0 hx:justify-center hx:pb-8 hx:pr-[calc(env(safe-area-inset-right)-1.5rem)]">
<main class="hx:w-full hx:min-w-0 hx:max-w-6xl hx:px-6 hx:pt-4 hx:md:px-12">
<br class="hx:mt-1.5 hx:text-sm" />
{{ if .Title }}<h1 class="hx:text-center hx:mt-2 hx:text-4xl hx:font-bold hx:tracking-tight hx:text-slate-900 hx:dark:text-slate-100">{{ .Title }}</h1>{{ end }}
<div class="hx:mb-16"></div>
<div class="content">
{{ .Content }}
</div>
<div>
{{- range .Pages -}}
<div>
<h3>
<a
style="color: inherit; text-decoration: none;"
class="hx:block hx:font-semibold hx:mt-8 hx:text-2xl"
href="{{ .RelPermalink }}"
title="{{ .LinkTitle }}"
>
{{ .Title }}
</a>
</h3>
<p class="hx:opacity-50 hx:text-sm hx:leading-7">{{ partial "utils/format-date" .Date }}</p>
</div>
{{- end -}}
</div>
</main>
</article>
</div>
{{ end }}
うごいたよね?
うちの環境ではこれで動いた。
最終更新日