mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-29 03:53:30 +08:00
refactor: add taxonomy
widget
Replaces `categories` and `tag-cloud` widget.
This commit is contained in:
parent
06f0f6068c
commit
0634317a55
@ -158,11 +158,15 @@ params:
|
|||||||
- type: archives
|
- type: archives
|
||||||
params:
|
params:
|
||||||
limit: 5
|
limit: 5
|
||||||
- type: categories
|
- type: taxonomy
|
||||||
params:
|
params:
|
||||||
|
type: categories
|
||||||
|
icon: categories
|
||||||
limit: 10
|
limit: 10
|
||||||
- type: tag-cloud
|
- type: taxonomy
|
||||||
params:
|
params:
|
||||||
|
type: tags
|
||||||
|
icon: tag
|
||||||
limit: 10
|
limit: 10
|
||||||
page:
|
page:
|
||||||
- type: toc
|
- type: toc
|
||||||
|
@ -1,17 +1,8 @@
|
|||||||
{{- $scope := default "homepage" .Scope -}}
|
{{- $scope := default "homepage" .Scope -}}
|
||||||
{{- $context := .Context -}}
|
{{- $context := .Context -}}
|
||||||
{{- $isCategoriesPage := and (eq $context.Kind "taxonomy") (eq $context.Type "categories") }}
|
|
||||||
{{- $isTagsPage := and (eq $context.Kind "taxonomy") (eq $context.Type "tags") }}
|
|
||||||
{{- with (index .Context.Site.Params.widgets $scope) -}}
|
{{- with (index .Context.Site.Params.widgets $scope) -}}
|
||||||
<aside class="sidebar right-sidebar sticky">
|
<aside class="sidebar right-sidebar sticky">
|
||||||
{{ range $widget := . }}
|
{{ range $widget := . }}
|
||||||
{{ if and $isCategoriesPage (eq .type "categories") }}
|
|
||||||
{{ continue }}
|
|
||||||
{{ end }}
|
|
||||||
{{ if and $isTagsPage (eq .type "tag-cloud") }}
|
|
||||||
{{ continue }}
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{ if templates.Exists (printf "partials/widget/%s.html" .type) }}
|
{{ if templates.Exists (printf "partials/widget/%s.html" .type) }}
|
||||||
{{ partial (printf "widget/%s" .type) (dict "Context" $context "Params" .params) }}
|
{{ partial (printf "widget/%s" .type) (dict "Context" $context "Params" .params) }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
{{- $query := first 1 (where (where .Context.Site.Pages "Kind" "taxonomy") "Type" "categories") -}}
|
|
||||||
{{- $context := .Context -}}
|
|
||||||
{{- $limit := default 10 .Params.limit -}}
|
|
||||||
{{- if $query -}}
|
|
||||||
{{- $categoriesPage := index $query 0 -}}
|
|
||||||
<section class="widget tagCloud">
|
|
||||||
<div class="widget-icon">
|
|
||||||
{{ partial "helper/icon" "categories" }}
|
|
||||||
</div>
|
|
||||||
<h2 class="widget-title section-title">
|
|
||||||
<a class="widget-link" href="{{ $categoriesPage.RelPermalink }}">{{ default "Categories" $categoriesPage.Title }}</a>
|
|
||||||
</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>
|
|
||||||
{{- else -}}
|
|
||||||
{{- warnf "Categories page not found. Please enable the categories taxonomy." -}}
|
|
||||||
{{- end -}}
|
|
@ -1,24 +0,0 @@
|
|||||||
{{- $query := first 1 (where (where .Context.Site.Pages "Kind" "taxonomy") "Type" "tags") -}}
|
|
||||||
{{- $context := .Context -}}
|
|
||||||
{{- $limit := default 10 .Params.limit -}}
|
|
||||||
{{- if $query -}}
|
|
||||||
{{- $tagsPage := index $query 0 -}}
|
|
||||||
<section class="widget tagCloud">
|
|
||||||
<div class="widget-icon">
|
|
||||||
{{ partial "helper/icon" "tag" }}
|
|
||||||
</div>
|
|
||||||
<h2 class="widget-title section-title">
|
|
||||||
<a class="widget-link" href="{{ $tagsPage.RelPermalink }}">{{ default "Tags" $tagsPage.Title }}</a>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<div class="tagCloud-tags">
|
|
||||||
{{ range first $limit $context.Site.Taxonomies.tags.ByCount }}
|
|
||||||
<a href="{{ .Page.RelPermalink }}" class="font_size_{{ .Count }}">
|
|
||||||
{{ .Page.Title }}
|
|
||||||
</a>
|
|
||||||
{{ end }}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
{{- else -}}
|
|
||||||
{{- warnf "Categories page not found. Please enable the categories taxonomy." -}}
|
|
||||||
{{- end -}}
|
|
32
layouts/partials/widget/taxonomy.html
Normal file
32
layouts/partials/widget/taxonomy.html
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
{{- $query := first 1 (where (where .Context.Site.Pages "Kind" "taxonomy") "Type" .Params.type) -}}
|
||||||
|
{{- $context := .Context -}}
|
||||||
|
{{- $limit := default 10 .Params.limit -}}
|
||||||
|
{{- $hideInTaxonomyPage := default true .Params.hideInTaxonomyPage -}}
|
||||||
|
{{- if $query -}}
|
||||||
|
{{- $taxonomyPage := index $query 0 -}}
|
||||||
|
{{- $isTaxonomyPage := eq .Context $taxonomyPage -}}
|
||||||
|
{{- if not (and $isTaxonomyPage $hideInTaxonomyPage) -}}
|
||||||
|
<section class="widget tagCloud">
|
||||||
|
<div class="widget-icon">
|
||||||
|
{{ partial "helper/icon" (default "tag" .Params.icon) }}
|
||||||
|
</div>
|
||||||
|
<h2 class="widget-title section-title">
|
||||||
|
<a class="widget-link" href="{{ $taxonomyPage.RelPermalink }}">
|
||||||
|
{{ default $taxonomyPage.Title .Params.title }}
|
||||||
|
</a>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="tagCloud-tags">
|
||||||
|
{{ $pages := index $context.Site.Taxonomies .Params.type }}
|
||||||
|
{{ $pagesSorted := $pages.ByCount }}
|
||||||
|
{{ range first $limit $pagesSorted }}
|
||||||
|
<a href="{{ .Page.RelPermalink }}" class="font_size_{{ .Count }}">
|
||||||
|
{{ .Page.Title }}
|
||||||
|
</a>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{{- end -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- warnf "Taxonomy [%s] not found." .Params.type -}}
|
||||||
|
{{- end -}}
|
Loading…
Reference in New Issue
Block a user