1
0
hugo/content/blog/2020-05-27-hugo.md

34 lines
1.1 KiB
Markdown
Raw Normal View History

2024-04-23 13:21:26 +00:00
+++
date = "2020-05-27"
tags = ["hugo"]
title = "タグを表示するようにしてみた"
slug = "hugo"
+++
[/tags](/tags)
タグは表示すると、整理したり、管理したり、付けるのも考えるのも覚えてるのも面倒だったりするので、表示していなかったのですが、他のブログ見てるとき、やっぱりタグあると便利だよなあと思ったので記事中に表示するようにしました。
```html:layout/_default/single.html
{{ $taxo := "tags" }}
{{ with .Param $taxo }}
<strong>tag{{ if gt (len .) 1 }}s{{ end }}:</strong>
{{ range $index, $director := . }}
{{- if gt $index 0 }}, {{ end -}}
{{ with $.Site.GetPage (printf "/%s/%s" $taxo $director) -}}
<a href="{{ .Permalink }}">{{ $director }}</a>
{{- 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 }}
<span class="tag"><a href="{{ "/tags/" | relLangURL }}{{ $termName | urlize }}">{{ $termName }}</a></span>
{{- end }}
{{ end }}
```