Merge pull request #109 from CaiJimmy/refactor-widget
feat(widget): detect automatically path to archives / search page
This commit is contained in:
commit
ced387cbd5
@ -60,7 +60,6 @@ params:
|
|||||||
|
|
||||||
archives:
|
archives:
|
||||||
limit: 5
|
limit: 5
|
||||||
path: archives
|
|
||||||
|
|
||||||
tagCloud:
|
tagCloud:
|
||||||
limit: 10
|
limit: 10
|
||||||
@ -82,7 +81,7 @@ params:
|
|||||||
colorScheme:
|
colorScheme:
|
||||||
# Display toggle
|
# Display toggle
|
||||||
toggle: true
|
toggle: true
|
||||||
|
|
||||||
# Available values: auto, light, dark
|
# Available values: auto, light, dark
|
||||||
default: auto
|
default: auto
|
||||||
|
|
||||||
|
@ -1,27 +1,33 @@
|
|||||||
<section class="widget archives">
|
{{- $query := first 1 (where .Site.Pages "Layout" "==" "archives") -}}
|
||||||
<div class="widget-icon">
|
{{- if $query -}}
|
||||||
{{ partial "helper/icon" "infinity" }}
|
{{- $archivesPage := index $query 0 -}}
|
||||||
</div>
|
<section class="widget archives">
|
||||||
<h2 class="widget-title section-title">{{ T "widget.archives.title" }}</h2>
|
<div class="widget-icon">
|
||||||
|
{{ partial "helper/icon" "infinity" }}
|
||||||
|
</div>
|
||||||
|
<h2 class="widget-title section-title">{{ T "widget.archives.title" }}</h2>
|
||||||
|
|
||||||
{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
|
{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
|
||||||
{{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }}
|
{{ $notHidden := where .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 .Site.Params.widgets.archives.limit 1) ($archives) }}
|
||||||
{{- $id := lower (replace $item.Key " " "-") -}}
|
{{- $id := lower (replace $item.Key " " "-") -}}
|
||||||
<div class="archives-year">
|
<div class="archives-year">
|
||||||
<a href="{{ $.Site.Params.widgets.archives.path | relLangURL }}#{{ $id }}">
|
<a href="{{ $archivesPage.RelPermalink }}#{{ $id }}">
|
||||||
{{ if eq $index $.Site.Params.widgets.archives.limit }}
|
{{ if eq $index $.Site.Params.widgets.archives.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>
|
||||||
<span class="count">{{ len $item.Pages }}</span>
|
<span class="count">{{ len $item.Pages }}</span>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
{{- else -}}
|
||||||
|
{{- warnf "Archives page not found. Create a page with layout: archives." -}}
|
||||||
|
{{- end -}}
|
@ -1,10 +1,16 @@
|
|||||||
<form action="/search" class="search-form widget" {{ with .OutputFormats.Get "json" -}}data-json="{{ .Permalink }}" {{- end }}>
|
{{- $query := first 1 (where .Site.Pages "Layout" "==" "search") -}}
|
||||||
<p>
|
{{- if $query -}}
|
||||||
<label>{{ T "search.title" }}</label>
|
{{- $searchPage := index $query 0 -}}
|
||||||
<input name="keyword" required placeholder="{{ T `search.placeholder` }}" />
|
<form action="{{ $searchPage.RelPermalink }}" class="search-form widget" {{ with .OutputFormats.Get "json" -}}data-json="{{ .Permalink }}" {{- end }}>
|
||||||
|
<p>
|
||||||
<button title="Search">
|
<label>{{ T "search.title" }}</label>
|
||||||
{{ partial "helper/icon" "search" }}
|
<input name="keyword" required placeholder="{{ T `search.placeholder` }}" />
|
||||||
</button>
|
|
||||||
</p>
|
<button title="{{ T `search.title` }}">
|
||||||
</form>
|
{{ partial "helper/icon" "search" }}
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
{{- else -}}
|
||||||
|
{{- warnf "Search page not found. Create a page with layout: search." -}}
|
||||||
|
{{- end -}}
|
Loading…
Reference in New Issue
Block a user