From a99a1efa459893492ec9c1629a38862dfbd4f58c Mon Sep 17 00:00:00 2001 From: George Cushen Date: Tue, 14 Dec 2021 20:18:45 +0000 Subject: [PATCH] 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` --- wowchemy/layouts/_default/list.html | 14 ++---- .../partials/functions/render_view.html | 31 +++++++++++++ wowchemy/layouts/partials/li_citation.html | 42 ------------------ .../{li_card.html => views/card.html} | 4 +- wowchemy/layouts/partials/views/citation.html | 43 +++++++++++++++++++ .../layouts/partials/views/community/.gitkeep | 0 .../{li_compact.html => views/compact.html} | 4 +- .../{li_list.html => views/list.html} | 4 +- .../layouts/partials/widgets/featured.html | 12 +----- wowchemy/layouts/partials/widgets/pages.html | 12 +----- wowchemy/layouts/section/event.html | 12 ++---- wowchemy/layouts/section/post.html | 12 ++---- wowchemy/layouts/section/publication.html | 12 +----- wowchemy/layouts/shortcodes/cite.html | 17 ++------ 14 files changed, 99 insertions(+), 120 deletions(-) create mode 100644 wowchemy/layouts/partials/functions/render_view.html delete mode 100644 wowchemy/layouts/partials/li_citation.html rename wowchemy/layouts/partials/{li_card.html => views/card.html} (96%) create mode 100644 wowchemy/layouts/partials/views/citation.html create mode 100644 wowchemy/layouts/partials/views/community/.gitkeep rename wowchemy/layouts/partials/{li_compact.html => views/compact.html} (97%) rename wowchemy/layouts/partials/{li_list.html => views/list.html} (96%) diff --git a/wowchemy/layouts/_default/list.html b/wowchemy/layouts/_default/list.html index 9537c452..ea7ee996 100644 --- a/wowchemy/layouts/_default/list.html +++ b/wowchemy/layouts/_default/list.html @@ -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" . }} diff --git a/wowchemy/layouts/partials/functions/render_view.html b/wowchemy/layouts/partials/functions/render_view.html new file mode 100644 index 00000000..73a5058d --- /dev/null +++ b/wowchemy/layouts/partials/functions/render_view.html @@ -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)) }} diff --git a/wowchemy/layouts/partials/li_citation.html b/wowchemy/layouts/partials/li_citation.html deleted file mode 100644 index 20b68213..00000000 --- a/wowchemy/layouts/partials/li_citation.html +++ /dev/null @@ -1,42 +0,0 @@ -{{ $has_attachments := partial "functions/has_attachments" . }} - -
- - - {{/* APA Style */}} - {{ if eq (site.Params.publications.citation_style | default "apa") "apa" }} - - - ({{- .Date.Format "2006" -}}). - {{ .Title }}. - {{ if .Params.publication_short }} - {{- .Params.publication_short | markdownify -}}. - {{ else if .Params.publication }} - {{- .Params.publication | markdownify -}}. - {{ end }} -

{{ partial "page_links" (dict "page" . "is_list" 1) }}

- - {{/* MLA Style */}} - {{ else }} - - - {{ .Title }}. - {{ if .Params.publication_short }} - {{- .Params.publication_short | markdownify -}}, - {{ else if .Params.publication }} - {{- .Params.publication | markdownify -}}, - {{ end }} - {{- .Date.Format "2006" -}}. - - {{ if $has_attachments }} - - {{ end }} - - {{ end }} -
diff --git a/wowchemy/layouts/partials/li_card.html b/wowchemy/layouts/partials/views/card.html similarity index 96% rename from wowchemy/layouts/partials/li_card.html rename to wowchemy/layouts/partials/views/card.html index b51ec077..8361d7f6 100644 --- a/wowchemy/layouts/partials/li_card.html +++ b/wowchemy/layouts/partials/views/card.html @@ -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 }} -
+
{{ if eq $item.Type "event" }}