feat: support view for course archive & custom section archives

The fullback list view for archive pages did not previously support the `view` option, instead presenting lists in one specific format.

If a user creates a custom section name (e.g. `content/prj/`) that doesn't correspond with a built-in page type, they now have the option not to use the default list view by defining `view` in the associated `_index.md` file.

See https://github.com/wowchemy/wowchemy-hugo-modules/discussions/2323
This commit is contained in:
George Cushen 2021-06-06 14:07:08 +01:00
commit db4dcf6541
3 changed files with 20 additions and 24 deletions

View file

@ -4,29 +4,20 @@
<div class="universal-wrapper">
{{ with .Content }}
<div class="article-style">{{ . }}</div>
<div class="article-style">{{ . }}</div>
{{ end }}
{{ $paginator := .Paginate .Data.Pages }}
{{ $paginator := .Paginate .Pages }}
{{ range $paginator.Pages }}
{{ $link := .RelPermalink }}
{{ $target := "" }}
{{ with .Params.external_link }}
{{ $link = . }}
{{ $target = "target=\"_blank\" rel=\"noopener\"" }}
{{ if eq $.Params.view 1 }}
{{ partial "li_list" . }}
{{ else if eq $.Params.view 3 }}
{{ partial "li_card" . }}
{{ else if eq $.Params.view 4 }}
{{ partial "li_citation" . }}
{{ else }}
{{ partial "li_compact" . }}
{{ end }}
<div>
<h2><a href="{{$link}}" {{ $target | safeHTMLAttr }}>{{ .Title }}</a></h2>
<div class="article-style">
{{ if .Params.summary }}
{{ .Params.summary | plainify | emojify }}
{{ else if .Params.abstract }}
{{ .Params.abstract | plainify | emojify | truncate 250 }}
{{ else if .Summary }}
{{ .Summary | plainify | emojify }}
{{ end }}
</div>
</div>
{{ end }}
{{ partial "pagination" . }}

View file

@ -3,10 +3,15 @@
{{ $page := . }}
{{ $pdf_link := false }}
{{ $slug := $page.File.ContentBaseName }}
{{ $resource := $page.Resources.GetMatch (printf "%s.pdf" $slug) }}
{{ with $resource }}
{{ $pdf_link = true }}
{{/* Prevent Hugo warning ".File.ContentBaseName on zero object." for content not backed by a Markdown file, */}}
{{/* such as auto-generated taxonomy pages, and sections without an explicit index file. */}}
{{/* The file check is required when called from `_default/list.html`, the fallback list view for the above cases. */}}
{{ with $page.File }}
{{ $slug := $page.File.ContentBaseName }}
{{ $resource := $page.Resources.GetMatch (printf "%s.pdf" $slug) }}
{{ with $resource }}
{{ $pdf_link = true }}
{{ end }}
{{ end }}
{{ $cite_link := false }}

View file

@ -1,5 +1,5 @@
{{ if or (.Paginator.HasPrev) (.Paginator.HasNext) }}
<nav>
<nav class="mt-1">
<ul class="pagination justify-content-center">
{{ if .Paginator.HasPrev }}
<li class="page-item"><a class="page-link" href="{{ .Paginator.Prev.URL }}">&laquo;</a></li>