diff options
author | Darshan Baral <darshanbaral@gmail.com> | 2019-07-07 21:21:22 +0300 |
---|---|---|
committer | Darshan Baral <darshanbaral@gmail.com> | 2019-07-07 21:21:22 +0300 |
commit | dfe7c74bd49cb69a39597a31cc5bec0a4d6222bc (patch) | |
tree | 2f94246523d93af761559841380caa8c0b86c015 /layouts | |
parent | 34be0b78b1ca6a0c1e7ab2b9d224899f860f073c (diff) |
when count is 1, taxa leads to single
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/index.html | 2 | ||||
-rw-r--r-- | layouts/partials/taxa.html | 51 |
2 files changed, 37 insertions, 16 deletions
diff --git a/layouts/index.html b/layouts/index.html index 112542a..8dd694b 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -16,7 +16,7 @@ <div class="standard"> <h1 class="top-h1 mb-4">Taxa</h1> <div class="p-3 bg-light shadow border rounded"> - {{ partial "taxa" (dict "this" .Site.Taxonomies "showAll" true) }} + {{ partial "taxa" (dict "taxo" .Site.Taxonomies "mysite" .) }} </div> </div> </div> diff --git a/layouts/partials/taxa.html b/layouts/partials/taxa.html index 83cf655..4784b9c 100644 --- a/layouts/partials/taxa.html +++ b/layouts/partials/taxa.html @@ -1,25 +1,46 @@ {{ $scratch := newScratch }} {{ $scratch.Delete "custom" }} -{{ $flag := .showAll }} -{{ range $name, $value := .this }} +{{ range $name, $value := .taxo }} {{ $scratch.Add "custom" (slice (dict "Name" $name "Value" $value "Num" (len $value))) }} {{ end }} {{ range sort ($scratch.Get "custom") ".Num" "desc" }} {{ $taxaTypeName := .Name }} - <h2> - {{ $taxaTypeName | humanize }}{{if $flag }}<small class="badge" title="Number of unique {{ $taxaTypeName | humanize }}">({{ .Num }})</small - >{{ end }} - </h2> - {{ $n_taxa := cond $flag .Num 5 }} - {{ $this_taxa := index $.this .Name }} - <div class="d-flex flex-row flex-wrap ml-2 mb-4"> - {{ range first $n_taxa $this_taxa.ByCount }} - <div class="m-1 p-1 btn btn-light border border-secondary"> - <a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a - > - <small title="Number of articles with {{ $taxaTypeName | singularize | humanize }} '{{ .Page.Title }}'">{{ .Count }}</small> - </div> - {{ end }} +<h2> + {{ $taxaTypeName | humanize }} + <small title="Number of unique {{ $taxaTypeName | humanize }}"> + ({{ .Num }}) + </small> +</h2> +{{ $this_taxa := index $.taxo .Name }} +<div class="d-flex flex-row flex-wrap ml-2 mb-4"> + {{ range $this_taxa.ByCount }} + {{ $count := .Count }} + {{ $taxaValueName := .Page.Title }} + {{ if eq $count 1 }} + {{ with (index .Pages 0) }} + <div class="m-1 p-1 btn btn-light border border-secondary"> + <a href="{{ .Permalink }}">{{ $taxaValueName }}</a> - + <small + title="Only one article titled '{{ .Title }}' has {{ $taxaTypeName | singularize | humanize }} '{{ $taxaValueName }}'" + > + {{- $count -}} + </small + > </div> + {{ end }} + {{ else }} + <div class="m-1 p-1 btn btn-light border border-secondary"> + <a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> - + <small + title="Number of articles with {{ $taxaTypeName | singularize | humanize }} '{{ $taxaValueName }}'" + > + {{- $count -}} + </small + > + </div> + {{ end }} + {{ end }} +</div> {{ end }} |