mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-06-18 20:13:31 +08:00
feat: article page widget support
This commit is contained in:
parent
ce57ea915e
commit
811a4e7c81
@ -132,16 +132,17 @@ params:
|
|||||||
host:
|
host:
|
||||||
id:
|
id:
|
||||||
widgets:
|
widgets:
|
||||||
enabled:
|
homepage:
|
||||||
- search
|
- type: search
|
||||||
- archives
|
- type: archives
|
||||||
- tag-cloud
|
params:
|
||||||
|
limit: 5
|
||||||
|
- type: tag-cloud
|
||||||
|
params:
|
||||||
|
limit: 10
|
||||||
|
|
||||||
archives:
|
page:
|
||||||
limit: 5
|
- type: toc
|
||||||
|
|
||||||
tagCloud:
|
|
||||||
limit: 10
|
|
||||||
|
|
||||||
opengraph:
|
opengraph:
|
||||||
twitter:
|
twitter:
|
||||||
|
@ -77,5 +77,5 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ define "right-sidebar" }}
|
{{ define "right-sidebar" }}
|
||||||
{{ partialCached "sidebar/right.html" . }}
|
{{ partial "sidebar/right.html" (dict "Context" . "Scope" "homepage") }}
|
||||||
{{ end }}
|
{{ end }}
|
@ -44,18 +44,5 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ define "right-sidebar" }}
|
{{ define "right-sidebar" }}
|
||||||
{{ if (.Scratch.Get "hasTOC") }}
|
{{ partial "sidebar/right.html" (dict "Context" . "Scope" "page") }}
|
||||||
<aside class="sidebar right-sidebar sticky">
|
|
||||||
<section class="widget archives">
|
|
||||||
<div class="widget-icon">
|
|
||||||
{{ partial "helper/icon" "hash" }}
|
|
||||||
</div>
|
|
||||||
<h2 class="widget-title section-title">{{ T "article.tableOfContents" }}</h2>
|
|
||||||
|
|
||||||
<div class="widget--toc">
|
|
||||||
{{ .TableOfContents }}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</aside>
|
|
||||||
{{ end }}
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -15,5 +15,5 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ define "right-sidebar" }}
|
{{ define "right-sidebar" }}
|
||||||
{{ partial "sidebar/right.html" . }}
|
{{ partial "sidebar/right.html" (dict "Context" . "Scope" "homepage") }}
|
||||||
{{ end }}
|
{{ end }}
|
@ -1,8 +1,13 @@
|
|||||||
{{ if .Site.Params.widgets.enabled }}
|
{{- $scope := default "homepage" .Scope -}}
|
||||||
{{ $context := . }}
|
{{- $context := .Context -}}
|
||||||
|
{{- with (index .Context.Site.Params.widgets $scope) -}}
|
||||||
<aside class="sidebar right-sidebar sticky">
|
<aside class="sidebar right-sidebar sticky">
|
||||||
{{ range $widget := .Site.Params.widgets.enabled }}
|
{{ range $widget := . }}
|
||||||
{{ partial (printf "widget/%s" $widget) $context }}
|
{{ if templates.Exists (printf "partials/widget/%s.html" .type) }}
|
||||||
|
{{ partial (printf "widget/%s" .type) (dict "Context" $context "Params" .params) }}
|
||||||
|
{{ else }}
|
||||||
|
{{ warnf "Widget %s not found" .type }}
|
||||||
|
{{ end}}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</aside>
|
</aside>
|
||||||
{{ end }}
|
{{ end }}
|
@ -1,4 +1,6 @@
|
|||||||
{{- $query := first 1 (where .Site.Pages "Layout" "==" "archives") -}}
|
{{- $query := first 1 (where .Context.Site.Pages "Layout" "==" "archives") -}}
|
||||||
|
{{- $context := .Context -}}
|
||||||
|
{{- $limit := default 5 .Params.limit -}}
|
||||||
{{- if $query -}}
|
{{- if $query -}}
|
||||||
{{- $archivesPage := index $query 0 -}}
|
{{- $archivesPage := index $query 0 -}}
|
||||||
<section class="widget archives">
|
<section class="widget archives">
|
||||||
@ -7,17 +9,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<h2 class="widget-title section-title">{{ T "widget.archives.title" }}</h2>
|
<h2 class="widget-title section-title">{{ T "widget.archives.title" }}</h2>
|
||||||
|
|
||||||
{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
|
{{ $pages := where $context.Site.RegularPages "Type" "in" $context.Site.Params.mainSections }}
|
||||||
{{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }}
|
{{ $notHidden := where $context.Site.RegularPages "Params.hidden" "!=" true }}
|
||||||
{{ $filtered := ($pages | intersect $notHidden) }}
|
{{ $filtered := ($pages | intersect $notHidden) }}
|
||||||
{{ $archives := $filtered.GroupByDate "2006" }}
|
{{ $archives := $filtered.GroupByDate "2006" }}
|
||||||
|
|
||||||
<div class="widget-archive--list">
|
<div class="widget-archive--list">
|
||||||
{{ range $index, $item := first (add .Site.Params.widgets.archives.limit 1) ($archives) }}
|
{{ range $index, $item := first (add $limit 1) ($archives) }}
|
||||||
{{- $id := lower (replace $item.Key " " "-") -}}
|
{{- $id := lower (replace $item.Key " " "-") -}}
|
||||||
<div class="archives-year">
|
<div class="archives-year">
|
||||||
<a href="{{ $archivesPage.RelPermalink }}#{{ $id }}">
|
<a href="{{ $archivesPage.RelPermalink }}#{{ $id }}">
|
||||||
{{ if eq $index $.Site.Params.widgets.archives.limit }}
|
{{ if eq $index $limit }}
|
||||||
<span class="year">{{ T "widget.archives.more" }}</span>
|
<span class="year">{{ T "widget.archives.more" }}</span>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<span class="year">{{ .Key }}</span>
|
<span class="year">{{ .Key }}</span>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{{- $query := first 1 (where .Site.Pages "Layout" "==" "search") -}}
|
{{- $query := first 1 (where .Context.Site.Pages "Layout" "==" "search") -}}
|
||||||
{{- if $query -}}
|
{{- if $query -}}
|
||||||
{{- $searchPage := index $query 0 -}}
|
{{- $searchPage := index $query 0 -}}
|
||||||
<form action="{{ $searchPage.RelPermalink }}" class="search-form widget" {{ with .OutputFormats.Get "json" -}}data-json="{{ .Permalink }}" {{- end }}>
|
<form action="{{ $searchPage.RelPermalink }}" class="search-form widget" {{ with .OutputFormats.Get "json" -}}data-json="{{ .Permalink }}" {{- end }}>
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
{{- $context := .Context -}}
|
||||||
|
{{- $limit := default 10 .Params.limit -}}
|
||||||
<section class="widget tagCloud">
|
<section class="widget tagCloud">
|
||||||
<div class="widget-icon">
|
<div class="widget-icon">
|
||||||
{{ partial "helper/icon" "tag" }}
|
{{ partial "helper/icon" "tag" }}
|
||||||
@ -5,7 +7,7 @@
|
|||||||
<h2 class="widget-title section-title">{{ T "widget.tagCloud.title" }}</h2>
|
<h2 class="widget-title section-title">{{ T "widget.tagCloud.title" }}</h2>
|
||||||
|
|
||||||
<div class="tagCloud-tags">
|
<div class="tagCloud-tags">
|
||||||
{{ range first .Site.Params.widgets.tagCloud.limit .Site.Taxonomies.tags.ByCount }}
|
{{ range first $limit $context.Site.Taxonomies.tags.ByCount }}
|
||||||
<a href="{{ .Page.RelPermalink }}" class="font_size_{{ .Count }}">
|
<a href="{{ .Page.RelPermalink }}" class="font_size_{{ .Count }}">
|
||||||
{{ .Page.Title }}
|
{{ .Page.Title }}
|
||||||
</a>
|
</a>
|
||||||
|
12
layouts/partials/widget/toc.html
Normal file
12
layouts/partials/widget/toc.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{{ if (.Context.Scratch.Get "hasTOC") }}
|
||||||
|
<section class="widget archives">
|
||||||
|
<div class="widget-icon">
|
||||||
|
{{ partial "helper/icon" "hash" }}
|
||||||
|
</div>
|
||||||
|
<h2 class="widget-title section-title">{{ T "article.tableOfContents" }}</h2>
|
||||||
|
|
||||||
|
<div class="widget--toc">
|
||||||
|
{{ .Context.TableOfContents }}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{{ end }}
|
Loading…
Reference in New Issue
Block a user