hugo-theme-stack/layouts/_default/archives.html
Jimmy Cai 5d100a7f99
feat: new archives layout (#989)
* feat(archives): add search bar to archives page

* fix: error `file is nil; wrap it in if or with` from Hugo 0.123.0

* style: rename `search.ts` to `archives.ts`

* refactor: remove `search` page layout

* doc: remove `search` from `exampleSite`

* fix: generate JSON output for archives page in exampleSite

* feat: put archives search form under categories list
2024-03-25 00:02:47 +01:00

63 lines
2.3 KiB
HTML

{{ define "body-class" }}template-archives template-search{{ end }}
{{ define "head" }}
{{- with .OutputFormats.Get "json" -}}
<link rel="preload" href="{{ .RelPermalink }}" as="fetch" crossorigin="anonymous">
{{- end -}}
{{ end }}
{{ define "main" }}
{{- $taxonomy := $.Site.GetPage "taxonomyTerm" "categories" -}}
{{- $terms := $taxonomy.Pages -}}
{{ if $terms }}
<header>
<h2 class="section-title">{{ $taxonomy.Title }}</h2>
<div class="subsection-list">
<div class="article-list--tile">
{{ range $terms }}
{{ partial "article-list/tile" (dict "context" . "size" "250x150" "Type" "taxonomy") }}
{{ end }}
</div>
</div>
</header>
{{ end }}
<form id="search-form" action="{{ .RelPermalink }}" class="search-form"{{ with .OutputFormats.Get "json" -}} data-json="{{ .RelPermalink }}"{{- end }}>
<p>
<label>{{ T "search.title" }}</label>
<input name="keyword" placeholder="{{ T `search.placeholder` }}" />
</p>
<button title="{{ T `search.title` }}">
{{ partial "helper/icon" "search" }}
</button>
</form>
<h3 class="search-result--title section-title"></h3>
{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
{{ range $pages.GroupByDate "2006" }}
{{ $id := lower (replace .Key " " "-") }}
<div class="archives-group" id="{{ $id }}">
<h2 class="archives-date section-title"><a href="{{ $.RelPermalink }}#{{ $id }}">{{ .Key }}</a></h2>
<div class="article-list--compact">
{{ range .Pages }}
{{ partial "article-list/compact" . }}
{{ end }}
</div>
</div>
{{ end }}
{{ partialCached "footer/footer" . }}
<script>
window.searchResultTitleTemplate = "{{ T `search.resultTitle` }}"
</script>
{{- $opts := dict "minify" hugo.IsProduction -}}
{{- $archivesScript := resources.Get "ts/archives.ts" | js.Build $opts -}}
<script type="text/javascript" src="{{ $archivesScript.RelPermalink }}" defer></script>
{{ end }}
{{ define "right-sidebar" }}
{{ partial "sidebar/right.html" (dict "Context" . "Scope" "homepage") }}
{{ end }}