wp-go/internal/theme/wp/components/widget/archive.gohtml

38 lines
1.7 KiB
Plaintext

{{define "common/archives"}}
<section id="archives-2" class="widget widget_archive">
<h2 class="widget-title">{{.archivesConfig.title}}</h2>
{{ if eq .archivesConfig.dropdown 1}}
<label class="screen-reader-text" for="archives-dropdown-2">{{.archivesConfig.title}}</label>
<select id="archives-dropdown-2" name="archive-dropdown">
<option value="">选择月份</option>
{{range $k,$v := .archives}}
<option {{if and (eq $.archiveYear $v.Year) (eq $.archiveMonth $v.Month) }}selected{{end}} value="/p/date/{{$v.Year}}/{{$v.Month|printf "%02s"}}"> {{$v.Year}}年{{$v.Month}}月 {{if eq $.archivesConfig.count 1}}&nbsp;({{$v.Posts}}){{end}} </option>
{{end}}
</select>
<script>
/* <![CDATA[ */
(function() {
const dropdown = document.getElementById("archives-dropdown-2");
function onSelectChange() {
if ( dropdown.options[ dropdown.selectedIndex ].value !== '' ) {
document.location.href = this.options[ this.selectedIndex ].value;
}
}
dropdown.onchange = onSelectChange;
})();
/* ]]> */
</script>
{{else}}
<nav aria-label="{{.archiveTitle}}">
<ul>
{{range $k,$v := .archives}}
<li><a href="/p/date/{{$v.Year}}/{{$v.Month|printf "%02s"}}">{{$v.Year}}年{{$v.Month}}月 {{if eq $.showArchiveCount 1}}&nbsp;({{$v.Posts}}){{end}}</a>
</li>
{{end}}
</ul>
</nav>
{{end}}
</section>
{{end}}