瀏覽代碼

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
George Cushen 3 年之前
父節點
當前提交
db4dcf6541

+ 10 - 19
wowchemy/layouts/_default/list.html

@@ -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" . }}

+ 9 - 4
wowchemy/layouts/partials/functions/has_attachments.html

@@ -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 }}

+ 1 - 1
wowchemy/layouts/partials/pagination.html

@@ -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>