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.
This commit is contained in:
George Cushen 2021-01-16 20:24:05 +00:00
commit d4ecdca0eb
6 changed files with 43 additions and 36 deletions

View file

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

View file

@ -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 @@
</a>
{{ end }}
{{ if $show_buttons }}
{{ if $has_attachments }}
<div class="btn-links">
{{ partial "page_links" (dict "page" $item "is_list" 1) }}
</div>

View file

@ -1,3 +1,5 @@
{{ $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>
@ -29,7 +31,12 @@
{{- .Params.publication | markdownify -}},
{{ end }}
{{- .Date.Format "2006" -}}.
<p>{{ partial "page_links" (dict "page" . "is_list" 1) }}</p>
{{ if $has_attachments }}
<div class="btn-links">
{{ partial "page_links" (dict "page" $item "is_list" 1) }}
</div>
{{ end }}
{{ end }}
</div>

View file

@ -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 }}
</div>
{{ if $show_buttons }}
{{ if $has_attachments }}
<div class="btn-links">
{{ partial "page_links" (dict "page" $item "is_list" 1) }}
</div>

View file

@ -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" . }}
<div class="view-list-item">
<i class="{{$icon_pack}} {{$icon}} pub-icon" aria-hidden="true"></i>
<a href="{{$link}}" {{ $target | safeHTMLAttr }}>{{ $item.Title }}</a>
{{ if eq $item.Type "talk" }}
{{ if eq $item.Type "event" }}
<div class="article-metadata">
<span>
{{ partial "functions/get_event_dates" $item }}
@ -47,7 +46,7 @@
</div>
{{ end }}
{{ if $show_buttons }}
{{ if $has_attachments }}
<div class="btn-links">
{{ partial "page_links" (dict "page" $item "is_list" 1) }}
</div>

View file

@ -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 }}
<div class="btn-links mb-3">
{{ with .Params.external_link }}
<a class="btn btn-outline-primary my-1" href="{{ . }}" target="_blank" rel="noopener">{{ i18n "open_project_site" }}</a>
{{ end }}
{{ partial "page_links" (dict "page" $page "is_list" 0) }}
{{ partial "page_links" (dict "page" . "is_list" 0) }}
</div>
{{ end }}