diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index d449fc9..dddb0e1 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -132,16 +132,17 @@ params: host: id: widgets: - enabled: - - search - - archives - - tag-cloud + homepage: + - type: search + - type: archives + params: + limit: 5 + - type: tag-cloud + params: + limit: 10 - archives: - limit: 5 - - tagCloud: - limit: 10 + page: + - type: toc opengraph: twitter: diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 90e5b66..49a5c12 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -77,5 +77,5 @@ {{ end }} {{ define "right-sidebar" }} - {{ partialCached "sidebar/right.html" . }} + {{ partial "sidebar/right.html" (dict "Context" . "Scope" "homepage") }} {{ end }} \ No newline at end of file diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 8ce42e9..2b13597 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -44,18 +44,5 @@ {{ end }} {{ define "right-sidebar" }} - {{ if (.Scratch.Get "hasTOC") }} - - {{ end }} + {{ partial "sidebar/right.html" (dict "Context" . "Scope" "page") }} {{ end }} diff --git a/layouts/index.html b/layouts/index.html index 576faef..0cd0b88 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -15,5 +15,5 @@ {{ end }} {{ define "right-sidebar" }} - {{ partial "sidebar/right.html" . }} + {{ partial "sidebar/right.html" (dict "Context" . "Scope" "homepage") }} {{ end }} \ No newline at end of file diff --git a/layouts/partials/sidebar/right.html b/layouts/partials/sidebar/right.html index 24763bb..bcbd0f0 100644 --- a/layouts/partials/sidebar/right.html +++ b/layouts/partials/sidebar/right.html @@ -1,8 +1,13 @@ -{{ if .Site.Params.widgets.enabled }} - {{ $context := . }} +{{- $scope := default "homepage" .Scope -}} +{{- $context := .Context -}} +{{- with (index .Context.Site.Params.widgets $scope) -}} {{ end }} \ No newline at end of file diff --git a/layouts/partials/widget/archives.html b/layouts/partials/widget/archives.html index 4a92a30..1f2abc5 100644 --- a/layouts/partials/widget/archives.html +++ b/layouts/partials/widget/archives.html @@ -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 -}} {{- $archivesPage := index $query 0 -}}
@@ -7,17 +9,17 @@

{{ T "widget.archives.title" }}

- {{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }} - {{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }} + {{ $pages := where $context.Site.RegularPages "Type" "in" $context.Site.Params.mainSections }} + {{ $notHidden := where $context.Site.RegularPages "Params.hidden" "!=" true }} {{ $filtered := ($pages | intersect $notHidden) }} {{ $archives := $filtered.GroupByDate "2006" }}
- {{ 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 " " "-") -}}
- {{ if eq $index $.Site.Params.widgets.archives.limit }} + {{ if eq $index $limit }} {{ T "widget.archives.more" }} {{ else }} {{ .Key }} diff --git a/layouts/partials/widget/search.html b/layouts/partials/widget/search.html index 833f740..7b0fc73 100644 --- a/layouts/partials/widget/search.html +++ b/layouts/partials/widget/search.html @@ -1,4 +1,4 @@ -{{- $query := first 1 (where .Site.Pages "Layout" "==" "search") -}} +{{- $query := first 1 (where .Context.Site.Pages "Layout" "==" "search") -}} {{- if $query -}} {{- $searchPage := index $query 0 -}}
diff --git a/layouts/partials/widget/tag-cloud.html b/layouts/partials/widget/tag-cloud.html index 99b8e59..e64e5e2 100644 --- a/layouts/partials/widget/tag-cloud.html +++ b/layouts/partials/widget/tag-cloud.html @@ -1,3 +1,5 @@ +{{- $context := .Context -}} +{{- $limit := default 10 .Params.limit -}}
{{ partial "helper/icon" "tag" }} @@ -5,7 +7,7 @@

{{ T "widget.tagCloud.title" }}

- {{ range first .Site.Params.widgets.tagCloud.limit .Site.Taxonomies.tags.ByCount }} + {{ range first $limit $context.Site.Taxonomies.tags.ByCount }} {{ .Page.Title }} diff --git a/layouts/partials/widget/toc.html b/layouts/partials/widget/toc.html new file mode 100644 index 0000000..0869cf2 --- /dev/null +++ b/layouts/partials/widget/toc.html @@ -0,0 +1,12 @@ +{{ if (.Context.Scratch.Get "hasTOC") }} +
+
+ {{ partial "helper/icon" "hash" }} +
+

{{ T "article.tableOfContents" }}

+ +
+ {{ .Context.TableOfContents }} +
+
+{{ end }} \ No newline at end of file