mirror of https://github.com/theNewDynamic/gohugo-theme-ananke.git

Patrick Kollitsch
yesterday 52ec6cd4b85f0d861100c6ab78bc2f8d3f073675
feat: show categories on posts (#973)

## Summary

* Add a `categories.html` partial that renders linked Hugo `categories`
terms with the same styling pattern used for tags.
* Include categories before tags on single pages.

## Motivation

Posts already show tags, but Hugo also supports `categories` as a
taxonomy. This resolves the requested single-page category display from
issue #620.

Closes #620

## Documentation

Documentation PR: gohugo-ananke/documentation#18

## Verification

* Compared `issues/620` against `development`; the branch is ahead by
only the intended two files.
* Confirmed `layouts/_partials/tags.html` already renders terms with
`.GetTerms "tags"`, and the new categories partial mirrors that approach
with `.GetTerms "categories"`.
* Could not run a local Hugo build because the execution container
cannot resolve `github.com` for repository cloning or dependency
installation.
2 files modified
1 files added
14 ■■■■■ changed files
config/_default/params.toml 1 ●●●● patch | view | raw | blame | history
layouts/_partials/categories.html 12 ●●●●● patch | view | raw | blame | history
layouts/single.html 1 ●●●● patch | view | raw | blame | history
config/_default/params.toml
@@ -1,5 +1,6 @@
[ananke]
show_recent_posts = true # show recent posts on the homepage
show_categories = true # show categories terms on single pages
[ananke.home]
content_alignment = "center" # options: left, center, right
layouts/_partials/categories.html
New file
@@ -0,0 +1,12 @@
{{- /* Show category terms on single pages unless disabled via site.Params.ananke.show_categories = false */ -}}
{{- if not (eq false site.Params.ananke.show_categories) -}}
<ul class="pa0">
  {{ range .GetTerms "categories" }}
   <li class="list di">
     <a href="{{ .RelPermalink }}" class="link f5 grow br-pill ba ph3 pv2 mb2 dib black sans-serif no-underline">
       {{- .LinkTitle -}}
     </a>
   </li>
  {{ end }}
</ul>
{{- end -}}
layouts/single.html
@@ -75,6 +75,7 @@
      {{- partials.Include "hook.html" (dict "hook" "content-before" "context" .) -}}
      {{- .Content -}}
      {{- partials.Include "hook.html" (dict "hook" "content-after" "context" .) -}}
      {{- partials.Include "categories.html" . -}}
      {{- partials.Include "tags.html" . -}}
      {{ if .Site.Config.Services.Disqus.Shortname }}
      <div class="mt6 instapaper_ignoref">