+++ date = "2020-05-27" tags = ["hugo"] title = "タグを表示するようにしてみた" slug = "hugo" +++ [/tags](/tags) タグは表示すると、整理したり、管理したり、付けるのも考えるのも覚えてるのも面倒だったりするので、表示していなかったのですが、他のブログ見てるとき、やっぱりタグあると便利だよなあと思ったので記事中に表示するようにしました。 ```html:layout/_default/single.html {{ $taxo := "tags" }} {{ with .Param $taxo }} tag{{ if gt (len .) 1 }}s{{ end }}: {{ range $index, $director := . }} {{- if gt $index 0 }}, {{ end -}} {{ with $.Site.GetPage (printf "/%s/%s" $taxo $director) -}} {{ $director }} {{- end -}} {{- end -}} {{ end }} ``` ```html:layout/_default/list.html {{ $s := path.Dir (.Permalink | relURL) }} {{ $t := index (split $s "/") 1 }} {{ if eq $t "tags" }} {{- range $termName, $index := .Site.Taxonomies.tags }} {{ $termName }} {{- end }} {{ end }} ```