refactor: create a generic taxonomy widget (#1268)
* refactor: introduce a generic taxonomy widget and refactor existing category and tag cloud widgets to use it. * feat: Implement optional title linking for taxonomy widgets and enable parameter customization for taxonomy partials. * refactor: remove fallback to taxonomy page title for widget display Because this field always exists. I think it's better to let user customize via widget params * Update layouts/_partials/widget/taxonomy.html * refactor: check for .Params.taxonomy existence before accessing
This commit is contained in:
@@ -1,16 +1,2 @@
|
||||
{{- $context := .Context -}}
|
||||
{{- $limit := default 10 .Params.limit -}}
|
||||
<section class="widget tagCloud">
|
||||
<div class="widget-icon">
|
||||
{{ partial "helper/icon" "categories" }}
|
||||
</div>
|
||||
<h2 class="widget-title section-title">{{ T "widget.categoriesCloud.title" }}</h2>
|
||||
|
||||
<div class="tagCloud-tags">
|
||||
{{ range first $limit $context.Site.Taxonomies.categories.ByCount }}
|
||||
<a href="{{ .Page.RelPermalink }}" class="font_size_{{ .Count }}">
|
||||
{{ .Page.Title }}
|
||||
</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
</section>
|
||||
{{ $params := merge (dict "taxonomy" "categories" "title" (T "widget.categoriesCloud.title") "icon" "categories") .Params }}
|
||||
{{ partial "widget/taxonomy" (dict "Context" .Context "Params" $params) }}
|
||||
@@ -1,16 +1,2 @@
|
||||
{{- $context := .Context -}}
|
||||
{{- $limit := default 10 .Params.limit -}}
|
||||
<section class="widget tagCloud">
|
||||
<div class="widget-icon">
|
||||
{{ partial "helper/icon" "tag" }}
|
||||
</div>
|
||||
<h2 class="widget-title section-title">{{ T "widget.tagCloud.title" }}</h2>
|
||||
|
||||
<div class="tagCloud-tags">
|
||||
{{ range first $limit $context.Site.Taxonomies.tags.ByCount }}
|
||||
<a href="{{ .Page.RelPermalink }}">
|
||||
{{ .Page.Title }}
|
||||
</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
</section>
|
||||
{{ $params := merge (dict "taxonomy" "tags" "title" (T "widget.tagCloud.title") "icon" "tag") .Params }}
|
||||
{{ partial "widget/taxonomy" (dict "Context" .Context "Params" $params) }}
|
||||
@@ -0,0 +1,39 @@
|
||||
{{- $context := .Context -}}
|
||||
|
||||
{{- if not .Params.taxonomy -}}
|
||||
{{- warnf "Taxonomy field is required" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $taxonomy := index $context.Site.Taxonomies .Params.taxonomy -}}
|
||||
{{- if not $taxonomy -}}
|
||||
{{- warnf "Taxonomy %s not found" .Params.taxonomy -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $taxonomyPage := $taxonomy.Page -}}
|
||||
{{- $widgetTitle := .Params.title -}}
|
||||
{{- $limit := default 10 .Params.limit -}}
|
||||
{{- $icon := default .Params.taxonomy .Params.icon -}}
|
||||
{{- $showLink := default false .Params.showLink -}}
|
||||
|
||||
<section class="widget tagCloud">
|
||||
<div class="widget-icon">
|
||||
{{ partial "helper/icon" $icon }}
|
||||
</div>
|
||||
<h2 class="widget-title section-title">
|
||||
{{ if $showLink }}
|
||||
<a href="{{ $taxonomyPage.RelPermalink }}">
|
||||
{{ $widgetTitle }}
|
||||
</a>
|
||||
{{ else }}
|
||||
{{ $widgetTitle }}
|
||||
{{ end }}
|
||||
</h2>
|
||||
|
||||
<div class="tagCloud-tags">
|
||||
{{ range first $limit $taxonomy.ByCount }}
|
||||
<a href="{{ .Page.RelPermalink }}">
|
||||
{{ .Page.Title }}
|
||||
</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
</section>
|
||||
Reference in New Issue
Block a user