feat: support community grid views

Third party, community views can be added to the new community folder, e.g. by creating a file at layouts/partials/views/community/MY_VIEW.html

And referencing it as `view: community/MY_VIEW`
This commit is contained in:
George Cushen committed 2021-12-14 20:18:45 +00:00
1 parent 36bc271272
commit a99a1efa45
14 files changed
+99 -120

No files matched your search

+3 -11
View File
@@ -8,17 +8,9 @@
{{ end }}
{{ $paginator := .Paginate .Pages }}
{{ range $paginator.Pages }}
{{ 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 }}
{{ end }}
{{ range $index, $post := $paginator.Pages }}
{{ partial "functions/render_view" (dict "page" $ "item" . "view" ($.Params.view | default "compact") "index" $index) }}
{{end}}
{{ partial "pagination" . }}
</div>
@@ -0,0 +1,31 @@
{{/* Wowchemy content preview renderer */}}
{{ $page := .page }}
{{ $item := .item }}
{{ $view := .view }}
{{ $view_file := "" }}
{{ $view_dtype := printf "%T" $view }}
{{ $index := .index }}
{{if eq $view_dtype "int" }}
{{/* Support legacy numeric views 1-4 */}}
{{ if eq $view 1 }}
{{ $view_file = "list" }}
{{ else if eq $view 3 }}
{{ $view_file = "card" }}
{{ else if eq $view 4 }}
{{ $view_file = "citation" }}
{{ else }}
{{ $view_file = "compact" }}
{{ end }}
{{else}}
{{ if templates.Exists (printf "partials/views/%s.html" (lower $view)) }}
{{ $view_file = lower $view }}
{{else}}
{{/* Fallback to compact view */}}
{{ warnf "Failed to locate view at `partials/views/%s.html`. Check you specified a supported `view` in `%s`" $view $page.File.Path }}
{{ $view_file = "compact" }}
{{end}}
{{ end }}
{{ return (partial (printf "views/%s" $view_file) (dict "page" $page "item" $item "index" $index)) }}
@@ -1,42 +0,0 @@
{{ $has_attachments := partial "functions/has_attachments" . }}
<div class="pub-list-item" style="margin-bottom: 1rem">
<i class="far fa-file-alt pub-icon" aria-hidden="true"></i>
{{/* APA Style */}}
{{ if eq (site.Params.publications.citation_style | default "apa") "apa" }}
<span class="article-metadata li-cite-author">
{{ partial "page_metadata_authors" . }}
</span>
({{- .Date.Format "2006" -}}).
<a href="{{ .RelPermalink }}">{{ .Title }}</a>.
{{ if .Params.publication_short }}
{{- .Params.publication_short | markdownify -}}.
{{ else if .Params.publication }}
{{- .Params.publication | markdownify -}}.
{{ end }}
<p>{{ partial "page_links" (dict "page" . "is_list" 1) }}</p>
{{/* MLA Style */}}
{{ else }}
<span class="article-metadata li-cite-author">
{{ partial "page_metadata_authors" . }}.
</span>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>.
{{ if .Params.publication_short }}
{{- .Params.publication_short | markdownify -}},
{{ else if .Params.publication }}
{{- .Params.publication | markdownify -}},
{{ end }}
{{- .Date.Format "2006" -}}.
{{ if $has_attachments }}
<div class="btn-links">
{{ partial "page_links" (dict "page" . "is_list" 1) }}
</div>
{{ end }}
{{ end }}
</div>
@@ -1,4 +1,4 @@
{{ $item := . }}
{{ $item := .item }}
{{/* Dynamic view adjusts to content type. */}}
{{ $has_attachments := partial "functions/has_attachments" . }}
@@ -13,7 +13,7 @@
{{ $summary = $item.Summary }}
{{ end }}
<div class="card-simple">
<div class="card-simple view-card">
{{ if eq $item.Type "event" }}
<div class="article-metadata">
@@ -0,0 +1,43 @@
{{ $item := .item }}
{{ $has_attachments := partial "functions/has_attachments" $item }}
<div class="pub-list-item view-citation" style="margin-bottom: 1rem">
<i class="far fa-file-alt pub-icon" aria-hidden="true"></i>
{{/* APA Style */}}
{{ if eq (site.Params.publications.citation_style | default "apa") "apa" }}
<span class="article-metadata li-cite-author">
{{ partial "page_metadata_authors" $item }}
</span>
({{- $item.Date.Format "2006" -}}).
<a href="{{ $item.RelPermalink }}">{{ $item.Title }}</a>.
{{ if $item.Params.publication_short }}
{{- $item.Params.publication_short | markdownify -}}.
{{ else if $item.Params.publication }}
{{- $item.Params.publication | markdownify -}}.
{{ end }}
<p>{{ partial "page_links" (dict "page" $item "is_list" 1) }}</p>
{{/* MLA Style */}}
{{ else }}
<span class="article-metadata li-cite-author">
{{ partial "page_metadata_authors" $item }}.
</span>
<a href="{{ $item.RelPermalink }}">{{ $item.Title }}</a>.
{{ if $item.Params.publication_short }}
{{- $item.Params.publication_short | markdownify -}},
{{ else if $item.Params.publication }}
{{- $item.Params.publication | markdownify -}},
{{ end }}
{{- $item.Date.Format "2006" -}}.
{{ if $has_attachments }}
<div class="btn-links">
{{ partial "page_links" (dict "page" $item "is_list" 1) }}
</div>
{{ end }}
{{ end }}
</div>
Whitespace-only changes.
@@ -1,4 +1,4 @@
{{ $item := . }}
{{ $item := .item }}
{{/* Dynamic view adjusts to content type. */}}
{{ $show_authors_only := false }}{{/* Show authors only or full metadata? */}}
@@ -28,7 +28,7 @@
{{ $summary = $item.Summary }}
{{ end }}
<div class="media stream-item">
<div class="media stream-item view-compact">
<div class="media-body">
<div class="section-subheading article-title mb-0 mt-0">
@@ -1,4 +1,4 @@
{{ $item := . }}
{{ $item := .item }}
{{/* Dynamic view adjusts to content type. */}}
{{ $icon_pack := "far" }}
@@ -24,7 +24,7 @@
{{ $has_attachments := partial "functions/has_attachments" . }}
<div class="view-list-item">
<div class="view-list view-list-item">
<i class="{{$icon_pack}} {{$icon}} pub-icon" aria-hidden="true"></i>
<a href="{{$link}}" {{ $target | safeHTMLAttr }}>{{ $item.Title }}</a>
@@ -56,16 +56,8 @@
{{ with $st.Content }}{{ . }}{{ end }}
{{ range $post := $query }}
{{ if eq $st.Params.design.view 1 }}
{{ partial "li_list" . }}
{{ else if eq $st.Params.design.view 3 }}
{{ partial "li_card" . }}
{{ else if eq $st.Params.design.view 4 | and (eq $items_type "publication") }}
{{ partial "li_citation" . }}
{{ else }}
{{ partial "li_compact" . }}
{{ end }}
{{ range $index, $post := $query }}
{{ partial "functions/render_view" (dict "page" $st "item" . "view" ($st.Params.design.view | default "compact") "index" $index) }}
{{end}}
{{/* Archive link */}}
+2 -10
View File
@@ -75,16 +75,8 @@
{{ with $st.Content }}{{ . }}{{ end }}
{{ range $post := $query }}
{{ if eq $st.Params.design.view 1 }}
{{ partial "li_list" . }}
{{ else if eq $st.Params.design.view 3 }}
{{ partial "li_card" . }}
{{ else if eq $st.Params.design.view 4 | and (eq $items_type "publication") }}
{{ partial "li_citation" . }}
{{ else }}
{{ partial "li_compact" . }}
{{ end }}
{{ range $index, $post := $query }}
{{ partial "functions/render_view" (dict "page" $st "item" . "view" ($st.Params.design.view | default "compact") "index" $index) }}
{{end}}
{{/* Archive link */}}
+3 -9
View File
@@ -17,15 +17,9 @@
</div>
<div class="col-lg-10">
{{ range .Pages }}
{{ if eq $.Params.view 1 }}
{{ partial "li_list" . }}
{{ else if eq $.Params.view 3 }}
{{ partial "li_card" . }}
{{ else }}
{{ partial "li_compact" . }}
{{ end }}
{{ end }}
{{ range $index, $item := .Pages }}
{{ partial "functions/render_view" (dict "page" $ "item" . "view" ($.Params.view | default "compact") "index" $index) }}
{{end}}
</div>
</div>
+3 -9
View File
@@ -9,15 +9,9 @@
{{ end }}
{{ $paginator := .Paginate .Data.Pages }}
{{ range $paginator.Pages }}
{{ if eq $.Params.view 1 }}
{{ partial "li_list" . }}
{{ else if eq $.Params.view 3 }}
{{ partial "li_card" . }}
{{ else }}
{{ partial "li_compact" . }}
{{ end }}
{{ end }}
{{ range $index, $item := $paginator.Pages }}
{{ partial "functions/render_view" (dict "page" $ "item" . "view" ($.Params.view | default "compact") "index" $index) }}
{{end}}
{{ partial "pagination" . }}
+2 -10
View File
@@ -48,7 +48,7 @@
</div>
<div id="container-publications">
{{ range .Pages.ByDate.Reverse }}
{{ range $index, $item := .Pages.ByDate.Reverse }}
{{ if .Params.publication_types }}
{{ $.Scratch.Set "pubtype" (index .Params.publication_types 0) }}
@@ -57,15 +57,7 @@
{{ end }}
<div class="grid-sizer col-lg-12 isotope-item pubtype-{{ $.Scratch.Get "pubtype" }} year-{{ .Date.Format "2006" }}">
{{ 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 }}
{{ partial "functions/render_view" (dict "page" $ "item" . "view" ($.Params.view | default "compact") "index" $index) }}
</div>
{{ end }}
+4 -13
View File
@@ -1,17 +1,8 @@
{{ $page := .Get "page" }}
{{ $item := .Get "page" }}
{{/* Default compact view. */}}
{{ $view := (.Get "view") | default 2 }}
{{ $view = int $view }}
{{ $view := (.Get "view") | default "compact" }}
{{ with site.GetPage $page }}
{{ if eq $view 1 }}
{{ partial "li_list" . }}
{{ else if eq $view 3 }}
{{ partial "li_card" . }}
{{ else if eq $view 4 }}
{{ partial "li_citation" . }}
{{ else }}
{{ partial "li_compact" . }}
{{ end }}
{{ with site.GetPage $item }}
{{ partial "functions/render_view" (dict "page" $ "item" . "view" $view "index" 0) }}
{{ end }}