From d4ecdca0eb969bb046067f175ce03dce9e0637d9 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sat, 16 Jan 2021 20:24:05 +0000 Subject: [PATCH] feat: show button links in listings irrespective of Type For example, if a blog post has an attachment, it will now be linked in the listing as well as in its page header. May also reduce excess spacing by preventing empty attachment DIV in the case of no attachments/buttons since it now checks if a page has buttons. --- .../partials/functions/has_attachments.html | 22 +++++++++++++++++++ wowchemy/layouts/partials/li_card.html | 10 ++------- wowchemy/layouts/partials/li_citation.html | 9 +++++++- wowchemy/layouts/partials/li_compact.html | 8 +++---- wowchemy/layouts/partials/li_list.html | 11 +++++----- wowchemy/layouts/partials/page_links_div.html | 19 +++------------- 6 files changed, 43 insertions(+), 36 deletions(-) create mode 100644 wowchemy/layouts/partials/functions/has_attachments.html diff --git a/wowchemy/layouts/partials/functions/has_attachments.html b/wowchemy/layouts/partials/functions/has_attachments.html new file mode 100644 index 00000000..4413c771 --- /dev/null +++ b/wowchemy/layouts/partials/functions/has_attachments.html @@ -0,0 +1,22 @@ +{{/* Return true if the page has attachments or link buttons to display. */}} + +{{ $page := . }} + +{{ $pdf_link := false }} +{{ $slug := $page.File.ContentBaseName }} +{{ $resource := $page.Resources.GetMatch (printf "%s.pdf" $slug) }} +{{ with $resource }} + {{ $pdf_link = true }} +{{ end }} + +{{ $cite_link := false }} +{{ $resource := $page.Resources.GetMatch "cite.bib" }} +{{ with $resource }} + {{ $cite_link = true }} +{{ end }} + +{{ if $cite_link | or $pdf_link | or .Params.url_preprint | or .Params.url_pdf | or .Params.url_slides | or .Params.url_video | or .Params.url_source | or .Params.url_code | or .Params.url_dataset | or .Params.url_poster | or .Params.url_project | or .Params.doi | or .Params.links | or .Params.projects | or .Params.slides }} + {{ return true }} +{{ else }} + {{ return false }} +{{ end }} diff --git a/wowchemy/layouts/partials/li_card.html b/wowchemy/layouts/partials/li_card.html index d58b1ba0..2529ab08 100644 --- a/wowchemy/layouts/partials/li_card.html +++ b/wowchemy/layouts/partials/li_card.html @@ -1,13 +1,7 @@ {{ $item := . }} - {{/* Dynamic view adjusts to content type. */}} -{{ $show_buttons := false }} -{{ if eq $item.Type "event" }} - {{ $show_buttons = true }} -{{ else if eq $item.Type "publication" }} - {{ $show_buttons = true }} -{{ end }} +{{ $has_attachments := partial "functions/has_attachments" . }} {{/* Get summary. */}} {{ $summary := "" }} @@ -63,7 +57,7 @@ {{ end }} - {{ if $show_buttons }} + {{ if $has_attachments }} diff --git a/wowchemy/layouts/partials/li_citation.html b/wowchemy/layouts/partials/li_citation.html index fc86e554..b550fa7a 100644 --- a/wowchemy/layouts/partials/li_citation.html +++ b/wowchemy/layouts/partials/li_citation.html @@ -1,3 +1,5 @@ +{{ $has_attachments := partial "functions/has_attachments" . }} +
@@ -29,7 +31,12 @@ {{- .Params.publication | markdownify -}}, {{ end }} {{- .Date.Format "2006" -}}. -

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

+ + {{ if $has_attachments }} + + {{ end }} {{ end }}
diff --git a/wowchemy/layouts/partials/li_compact.html b/wowchemy/layouts/partials/li_compact.html index 2bd2b058..f4d41d52 100644 --- a/wowchemy/layouts/partials/li_compact.html +++ b/wowchemy/layouts/partials/li_compact.html @@ -2,7 +2,6 @@ {{/* Dynamic view adjusts to content type. */}} {{ $show_authors_only := false }}{{/* Show authors only or full metadata? */}} -{{ $show_buttons := false }} {{ $link := $item.RelPermalink }} {{ $target := "" }} {{ if $item.Params.external_link }} @@ -11,15 +10,14 @@ {{ end }} {{ if eq $item.Type "event" }} {{ $show_authors_only = true }} - {{ $show_buttons = true }} {{ else if eq $item.Type "publication" }} {{ $show_authors_only = true }} - {{ $show_buttons = true }} {{ else if eq $item.Type "project" }} {{ $show_authors_only = true }} - {{ $show_buttons = true }} {{ end }} +{{ $has_attachments := partial "functions/has_attachments" . }} + {{/* Get summary. */}} {{ $summary := "" }} {{ if $item.Params.summary }} @@ -68,7 +66,7 @@ {{ end }} - {{ if $show_buttons }} + {{ if $has_attachments }} diff --git a/wowchemy/layouts/partials/li_list.html b/wowchemy/layouts/partials/li_list.html index 2600af05..1d9e1e16 100644 --- a/wowchemy/layouts/partials/li_list.html +++ b/wowchemy/layouts/partials/li_list.html @@ -4,7 +4,6 @@ {{ $icon_pack := "far" }} {{ $icon := "fa-file-alt" }} {{ $show_authors := false }} -{{ $show_buttons := false }} {{ $link := $item.RelPermalink }} {{ $target := "" }} {{ if $item.Params.external_link }} @@ -13,23 +12,23 @@ {{ end }} {{ if eq $item.Type "post" }} {{ $icon = "fa-newspaper" }} -{{ else if eq $item.Type "talk" }} +{{ else if eq $item.Type "event" }} {{ $icon = "fa-calendar-alt" }} {{ else if eq $item.Type "publication" }} {{ $show_authors = true }} - {{ $show_buttons = true }} {{ else if eq $item.Type "project" }} {{ $icon_pack = "fas" }} {{ $icon = "fa-project-diagram" }} {{ $show_authors = true }} - {{ $show_buttons = true }} {{ end }} +{{ $has_attachments := partial "functions/has_attachments" . }} +
{{ $item.Title }} - {{ if eq $item.Type "talk" }} + {{ if eq $item.Type "event" }} {{ end }} - {{ if $show_buttons }} + {{ if $has_attachments }} diff --git a/wowchemy/layouts/partials/page_links_div.html b/wowchemy/layouts/partials/page_links_div.html index fc1491f4..f27e1610 100644 --- a/wowchemy/layouts/partials/page_links_div.html +++ b/wowchemy/layouts/partials/page_links_div.html @@ -1,25 +1,12 @@ {{/* Div wrapper around page links. */}} {{/* The wrapper is hidden when the page has no link buttons. */}} -{{ $page := . }} -{{ $pdf_link := false }} -{{ $cite_link := false }} -{{ $slug := $page.File.ContentBaseName }} -{{ $resource := $page.Resources.GetMatch (printf "%s.pdf" $slug) }} -{{ with $resource }} - {{ $pdf_link = true }} -{{ end }} - -{{ $resource := $page.Resources.GetMatch "cite.bib" }} -{{ with $resource }} - {{ $cite_link = true }} -{{ end }} - -{{ if $cite_link | or $pdf_link | or .Params.external_link | or .Params.url_preprint | or .Params.url_pdf | or .Params.url_slides | or .Params.url_video | or .Params.url_source | or .Params.url_code | or .Params.url_dataset | or .Params.url_poster | or .Params.url_project | or .Params.doi | or .Params.links | or .Params.projects | or .Params.slides }} +{{ $has_attachments := partial "functions/has_attachments" . }} +{{ if $has_attachments | or .Params.external_link }} {{ end }}