use templates to generate tag and author labels

This commit is contained in:
Robert Kaussow 2020-07-08 20:52:38 +02:00
parent d659848a98
commit 2bfbea602c
No known key found for this signature in database
GPG Key ID: 65362AE74AF98B61

View File

@ -25,43 +25,51 @@
{{ $.Scratch.Set "author-counter" 0 }} {{ $.Scratch.Set "author-counter" 0 }}
{{ with .Params.authors }} {{ with .Params.authors }}
{{ range sort . }} {{ range sort . }}
{{ $i := $.Scratch.Get "author-counter" }} {{ $ac := $.Scratch.Get "author-counter" }}
{{ $author := index $.Site.Data.authors . }} {{ $author := index $.Site.Data.authors . }}
{{ with $.Site.GetPage (printf "/authors/%s" $author.name | urlize) }} {{ with $.Site.GetPage (printf "/authors/%s" $author.name | urlize) }}
{{ if eq $i 0 }} {{ if eq $ac 0 }}
<span class="no-wrap"> <span class="no-wrap">
<svg class="icon menu"><use xlink:href="#person"></use></svg> <svg class="icon person"><use xlink:href="#person"></use></svg>
{{ end }} {{ template "post-author" dict "name" $author.name "page" . }}
<span class="gblog-post__tag gblog-button">
<a class="gblog-button__link" href="{{ .RelPermalink }}" title="All posts of this author">{{ $author.name }}</a>
</span>
{{ if eq $i 0 }}
</span> </span>
{{ else }}
{{ template "post-author" dict "name" $author.name "page" . }}
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ $.Scratch.Set "author-counter" (add ($i) 1) }} {{ $.Scratch.Set "author-counter" (add $ac 1) }}
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ $.Scratch.Set "tag-counter" 0 }} {{ $.Scratch.Set "tag-counter" 0 }}
{{ with .Params.tags }} {{ with .Params.tags }}
{{ range sort . }} {{ range sort . }}
{{ $i := $.Scratch.Get "tag-counter" }} {{ $tc := $.Scratch.Get "tag-counter" }}
{{ $name := . }} {{ $name := . }}
{{ if eq $i 0 }}
<span class="no-wrap">
<svg class="icon menu"><use xlink:href="#tags"></use></svg>
{{ end }}
<span class="gblog-post__tag gblog-button">
{{ with $.Site.GetPage (printf "/tags/%s" $name | urlize) }} {{ with $.Site.GetPage (printf "/tags/%s" $name | urlize) }}
<a class="gblog-button__link" href="{{ .RelPermalink }}" title="All posts tagged with '{{ $name }}'">{{ $name }}</a> {{ if eq $tc 0 }}
{{ end }} <span class="no-wrap">
</span> <svg class="icon tags"><use xlink:href="#tags"></use></svg>
{{ if eq $i 0 }} {{ template "post-tag" dict "name" $name "page" . }}
</span> </span>
{{ else }}
{{ template "post-tag" dict "name" $name "page" . }}
{{ end }} {{ end }}
{{ $.Scratch.Set "tag-counter" (add ($i) 1) }} {{ end }}
{{ $.Scratch.Set "tag-counter" (add $tc 1) }}
{{ end }} {{ end }}
{{ end }} {{ end }}
</footer> </footer>
</article> </article>
{{ define "post-tag" }}
<span class="gblog-post__tag gblog-button">
<a class="gblog-button__link" href="{{ .page.RelPermalink }}" title="All posts tagged with '{{ .name }}'">{{ .name }}</a>
</span>
{{ end }}
{{ define "post-author" }}
<span class="gblog-post__tag gblog-button">
<a class="gblog-button__link" href="{{ .page.RelPermalink }}" title="All posts of this author">{{ .name }}</a>
</span>
{{ end }}