Skip to content

Commit

Permalink
feat(tailwind): port support for Publications and Events
Browse files Browse the repository at this point in the history
  • Loading branch information
gcushen committed May 6, 2024
1 parent 2261d9b commit 75a4222
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 4 deletions.
1 change: 1 addition & 0 deletions modules/blox-tailwind/assets/css/styles.css
Expand Up @@ -5,4 +5,5 @@
@import "main.css";
@import "./components/all.css";
@import "./blox/all.css";
@import "./views/attachments.css";
@import "chroma.css";
11 changes: 11 additions & 0 deletions modules/blox-tailwind/assets/css/views/attachments.css
@@ -0,0 +1,11 @@
.hb-attachment-link {
@apply inline-block text-primary-600 dark:text-primary-400 font-bold uppercase outline-none focus:outline-none mr-1 mb-1 ease-linear transition-all duration-150;
}

.hb-attachment-link-small {
@apply px-3 py-1 text-xs;
}

.hb-attachment-link-large {
@apply px-8 py-3;
}
4 changes: 2 additions & 2 deletions modules/blox-tailwind/assets/dist/wc.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions modules/blox-tailwind/data/address_formats.toml
@@ -0,0 +1,12 @@
# Address formats.
en-ca = {order = ['street', 'city', 'region', 'postcode', 'country'], delimiters = ['<br>', ', ', '<br>', '<br>']}
en-us = {order = ['street', 'city', 'region', 'postcode'], delimiters = [', ', ', ', ' ', '']}
en-gb = {order = ['street', 'city', 'region', 'postcode'], delimiters = [', ', ', ', ', ', '']}
de = {order = ['street', 'postcode', 'city'], delimiters = ['<br>', ' ', '']}
fr-ca = {order = ['street', 'city', 'region', 'postcode', 'country'], delimiters = ['<br>', ', ', '<br>', '<br>']}
fr-fr = {order = ['street', 'postcode', 'city'], delimiters = ['<br>', ' ', '']}
nl = {order = ['street', 'postcode', 'city', 'country'], delimiters = ['<br>', ' ', '<br>', '']}
zh = {order = ['postcode', 'region', 'city', 'street'], delimiters = [' ', ' ', ' ', '']}
pt-br = {order = ['street', 'city', 'region', 'postcode', 'country'], delimiters = ['<br>', ', ', '<br>', '<br>']}
il = {order = ['street', 'city', 'postcode', 'country'], delimiters = [', ', '&nbsp;', ' ', '']}
fi = {order = ['street', 'postcode', 'city', 'country'], delimiters = [', ', ' ', ', ']}
73 changes: 72 additions & 1 deletion modules/blox-tailwind/layouts/_default/single.html
@@ -1,4 +1,14 @@
{{ define "main" }}

{{ $pub_type_csl := "" }}
{{ $pub_type_display := "" }}
{{ if .Params.publication_types }}
{{ if reflect.IsSlice .Params.publication_types }}
{{ $pub_type_csl = index .Params.publication_types 0 }}
{{ $pub_type_display = i18n (printf "pub_%s" (strings.Replace $pub_type_csl "-" "_")) | default (strings.Title $pub_type_csl) }}
{{ end }}
{{ end }}

<div class="mx-auto flex max-w-screen-xl">
{{ partial "components/sidebar.html" (dict "context" . "no_sidebar" true) }}
{{ partial "components/toc.html" . }}
Expand All @@ -15,7 +25,8 @@ <h1 class="mt-2 text-4xl font-bold tracking-tight text-slate-900 dark:text-slate
{{- .Title -}}
</h1>

<div class="mt-4 mb-16 text-gray-500 dark:text-gray-300 text-sm flex items-center flex-wrap gap-y-2">
<div class="mt-4 mb-16">
<div class="text-gray-500 dark:text-gray-300 text-sm flex items-center flex-wrap gap-y-2">
{{- if .Date | and (not .Params.hide_date) -}}
<span class="mr-1">{{- .Date | time.Format (site.Params.locale.date_format | default ":date_long") -}}</span>
{{- if .Params.authors }}<span class="mx-1">·</span>{{ end -}}
Expand Down Expand Up @@ -47,8 +58,15 @@ <h1 class="mt-2 text-4xl font-bold tracking-tight text-slate-900 dark:text-slate
{{ .ReadingTime }} {{ i18n "minute_read" }}
</span>
{{ end }}
</div>

<div class="mt-3">
{{ partial "page_links_div.html" . }}
</div>
</div>



{{ $featured := partial "functions/get_featured_image.html" . }}
{{/* Featured image layout */}}
{{ if and $featured (not .Params.image.preview_only) }}
Expand Down Expand Up @@ -79,6 +97,59 @@ <h1 class="mt-2 text-4xl font-bold tracking-tight text-slate-900 dark:text-slate
</div>
{{end}}

{{/* EVENT / PUBLICATION METADATA */}}
{{ if .Params.abstract | or (eq .Type "publication") | or (eq .Type "event") }}
<div class="max-w-prose grid grid-cols-1 md:grid-cols-[200px_auto] gap-4 my-6">

{{ if .Params.abstract }}
<div class="font-bold text-2xl">{{ i18n "abstract" }}</div>
<div>{{ .Params.abstract | markdownify }}</div>
{{ end }}

{{/* If the type is Uncategorized, hide the type. */}}
{{ if $pub_type_display }}
<div class="font-bold text-2xl">{{ i18n "publication_type" }}</div>
<div>
<a href="{{ range first 1 (.GetTerms "publication_types") }}{{.RelPermalink}}{{end}}">
{{ $pub_type_display }}
</a>
</div>
{{ end }}

{{ if .Params.publication }}
<div class="font-bold text-2xl">{{ i18n "publication" }}</div>
<div>{{ .Params.publication | markdownify }}</div>
{{ end }}

{{ if eq .Type "event" }}
<div class="font-bold text-2xl">{{ i18n "date" }}</div>
<div>
{{ partial "functions/get_event_dates" . }}
</div>
{{ end }}

{{ if .Params.event }}
<div class="font-bold text-2xl">{{ i18n "event" }}</div>
<div>
{{ with .Params.event_url }}<a href="{{ . }}" target="_blank" rel="noopener">{{ end }}
{{ .Params.event | markdownify }}
{{ if .Params.event_url }}</a>{{ end }}
</div>
{{ end }}

{{ if .Params.location }}
<div class="font-bold text-2xl">{{ i18n "location" }}</div>
<div>
<p>{{ .Params.location | markdownify }}</p>
{{ if .Params.address }}
<p>{{partial "functions/get_address" (dict "root" . "address" .Params.address) }}</p>
{{end}}
</div>
{{ end }}

</div>
{{ end }}

<div class="prose prose-slate lg:prose-xl dark:prose-invert">
{{ .Content }}
</div>
Expand Down
23 changes: 23 additions & 0 deletions modules/blox-tailwind/layouts/partials/functions/get_address.html
@@ -0,0 +1,23 @@
{{/* Function to return a formatted address given a semantic address. */}}

{{/* Check for valid site config. */}}
{{ if not site.Data.address_formats }}{{errorf "Address formats missing from `data/address_formats.toml`!"}}{{end}}

{{ $page := . }}
{{ $address := .address }}
{{ $format_name := $page.Params.address_format | default site.Params.locale.address_format | default "en-us" }}

{{ if not (isset site.Data.address_formats $format_name) }}{{ errorf "Address format `%s` missing from `data/address_formats.toml`!" $format_name }}{{end}}

{{ $format := index site.Data.address_formats $format_name }}
{{ $address_display := slice }}

{{ range $k, $v := $format.order }}
{{ if eq $v "street" | and $address.street }}{{$address_display = $address_display | append (transform.HTMLEscape $address.street) | append (index $format.delimiters $k | default "") }}{{end}}
{{ if eq $v "city" | and $address.city }}{{$address_display = $address_display | append (transform.HTMLEscape $address.city) | append (index $format.delimiters $k | default "") }}{{end}}
{{ if eq $v "region" | and $address.region }}{{$address_display = $address_display | append (transform.HTMLEscape $address.region) | append (index $format.delimiters $k | default "") }}{{end}}
{{ if eq $v "postcode" | and $address.postcode }}{{$address_display = $address_display | append (transform.HTMLEscape $address.postcode) | append (index $format.delimiters $k | default "") }}{{end}}
{{ if eq $v "country" | and $address.country }}{{$address_display = $address_display | append (transform.HTMLEscape $address.country) | append (index $format.delimiters $k | default "") }}{{end}}
{{end}}

{{ return safeHTML (delimit $address_display "") }}
@@ -0,0 +1,17 @@
{{/* Function to get event start and end dates/times. */}}
{{ $t1 := time .Date }}{{/* Start datetime. */}}
{{ $str := slice (time.Format site.Params.locale.date_format (time $t1)) }}{{/* Init return string with start date. */}}
{{/* Show start time if not all day event. */}}
{{ if not .Params.all_day }}{{ $str = $str | append (time.Format site.Params.locale.time_format (time $t1)) }}{{ end }}
{{/* Show event end date if provided. */}}
{{ if .Params.date_end }}
{{ $str = $str | append "&mdash;" }}
{{ $t2 := time .Params.date_end}}{{/* End datetime. */}}
{{/* Show end date if it differs to start date. */}}
{{ if not (eq $t1.Year $t2.Year | and (eq $t1.Month $t2.Month) | and (eq $t1.Day $t2.Day)) }}
{{ $str = $str | append (time.Format site.Params.locale.date_format (time $t2)) }}
{{ end }}
{{/* Show end time if not all day event. */}}
{{ if not .Params.all_day }}{{ $str = $str | append (time.Format site.Params.locale.time_format (time $t2)) }}{{ end }}
{{ end }}
{{ return ((delimit $str " ") | safeHTML) }}
@@ -0,0 +1,23 @@
{{/* Return true if the page has attachments or link buttons to display. */}}

{{ $page := . }}

{{ $pdf_link := false }}
{{/* 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 }}
{{ $resource := $page.Resources.GetMatch "cite.bib" }}
{{ with $resource }}
{{ $cite_link = true }}
{{ end }}

{{ return ($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) }}
167 changes: 167 additions & 0 deletions modules/blox-tailwind/layouts/partials/page_links.html
@@ -0,0 +1,167 @@
{{ $is_list := .is_list }}
{{ $page := .page }}
{{ $link := "" }}

{{/* ***** TODO: Deprecate `url_preprint` in favour of `url_pdf` given there's now a dedicated "Preprint" pub. type. ***** */}}
{{ with $page.Params.url_preprint }}
{{ $resource := $page.Resources.GetMatch . }}
{{ if $resource }}
{{ $link = $resource.RelPermalink }}
{{ else }}
{{ $link = . | relURL }}
{{ end }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
{{ i18n "btn_preprint" }}
</a>
{{ end }}
{{ $pdf := "" }}
{{ $resource := $page.Resources.GetMatch (printf "%s.pdf" $page.File.ContentBaseName) }}
{{ with $resource }}
{{ $pdf = .RelPermalink }}
{{ else }}
{{ if $page.Params.url_pdf }}
{{ $pdf = $page.Params.url_pdf | relURL }}
{{ end }}
{{ end }}

{{ with $pdf }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ . }}" target="_blank" rel="noopener">
{{ partial "functions/get_icon" (dict "name" "document-text" "attributes" "style=\"height: 1em\" class='inline-block'") }}
{{ i18n "btn_pdf" }}
</a>
{{ end }}
{{ $resource := $page.Resources.GetMatch "cite.bib" }}
{{ with $resource }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ .RelPermalink }}" target="_blank" data-filename="{{ .RelPermalink }}">
{{ partial "functions/get_icon" (dict "name" "document-duplicate" "attributes" "style=\"height: 1em\" class='inline-block'") }}
{{ i18n "btn_cite" }}
</a>
{{ end }}
{{ with $page.Params.url_code }}
{{ $resource := $page.Resources.GetMatch . }}
{{ if $resource }}
{{ $link = $resource.RelPermalink }}
{{ else }}
{{ $link = . | relURL }}
{{ end }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
{{ partial "functions/get_icon" (dict "name" "code-bracket" "attributes" "style=\"height: 1em\" class='inline-block'") }}
{{ i18n "btn_code" }}
</a>
{{ end }}
{{ with $page.Params.url_dataset }}
{{ $resource := $page.Resources.GetMatch . }}
{{ if $resource }}
{{ $link = $resource.RelPermalink }}
{{ else }}
{{ $link = . | relURL }}
{{ end }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
{{ partial "functions/get_icon" (dict "name" "circle-stack" "attributes" "style=\"height: 1em\" class='inline-block'") }}
{{ i18n "btn_dataset" }}
</a>
{{ end }}
{{ if $page.Params.projects }}
{{ range $page.Params.projects }}
{{ with (site.GetPage (printf "project/%s" .)) }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ .RelPermalink }}">
{{ i18n "btn_project" }}
</a>
{{ else }}
{{/* errorf "The `projects` parameter in `content/%s` references a project file, `content/project/%s`, which cannot be found. Please either set `projects = []` or fix the reference." $page.File.Path . */}}
{{ end }}
{{ end }}
{{ else }}
{{ with $page.Params.url_project }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ . }}" target="_blank" rel="noopener">
{{ i18n "btn_project" }}
</a>
{{ end }}
{{ end }}
{{ with $page.Params.url_poster }}
{{ $resource := $page.Resources.GetMatch . }}
{{ if $resource }}
{{ $link = $resource.RelPermalink }}
{{ else }}
{{ $link = . | relURL }}
{{ end }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
{{ partial "functions/get_icon" (dict "name" "photo" "attributes" "style=\"height: 1em\" class='inline-block'") }}
{{ i18n "btn_poster" }}
</a>
{{ end }}
{{ if $page.Params.slides }}
{{ with (site.GetPage (printf "slides/%s" $page.Params.slides)) }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ .RelPermalink }}" target="_blank">
{{ partial "functions/get_icon" (dict "name" "presentation-chart-bar" "attributes" "style=\"height: 1em\" class='inline-block'") }}
{{ i18n "btn_slides" }}
</a>
{{ end }}
{{ else }}
{{ with $page.Params.url_slides }}
{{ $resource := $page.Resources.GetMatch . }}
{{ if $resource }}
{{ $link = $resource.RelPermalink }}
{{ else }}
{{ $link = . | relURL }}
{{ end }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
{{ partial "functions/get_icon" (dict "name" "presentation-chart-bar" "attributes" "style=\"height: 1em\" class='inline-block'") }}
{{ i18n "btn_slides" }}
</a>
{{ end }}
{{ end }}
{{ with $page.Params.url_video }}
{{ $resource := $page.Resources.GetMatch . }}
{{ if $resource }}
{{ $link = $resource.RelPermalink }}
{{ else }}
{{ $link = . | relURL }}
{{ end }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
{{ partial "functions/get_icon" (dict "name" "video-camera" "attributes" "style=\"height: 1em\" class='inline-block'") }}
{{ i18n "btn_video" }}
</a>
{{ end }}
{{ with $page.Params.url_source }}
{{ $resource := $page.Resources.GetMatch . }}
{{ if $resource }}
{{ $link = $resource.RelPermalink }}
{{ else }}
{{ $link = . | relURL }}
{{ end }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
{{ partial "functions/get_icon" (dict "name" "document" "attributes" "style=\"height: 1em\" class='inline-block'") }}
{{ i18n "btn_source" }}
</a>
{{ end }}
{{ with $page.Params.doi }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="https://doi.org/{{ . }}" target="_blank" rel="noopener">
DOI
</a>
{{ end }}
{{ range $page.Params.links }}
{{ $pack := or .icon_pack "fas" }}
{{ $pack_prefix := $pack }}
{{ if in (slice "fab" "fas" "far" "fal") $pack }}
{{ $pack_prefix = "fa" }}
{{ end }}
{{ $link := .url | default "" }}
{{ $scheme := (urls.Parse $link).Scheme }}
{{ $target := "" }}
{{ if not $scheme }}
{{ $resource := $page.Resources.GetMatch $link }}
{{ if $resource }}
{{ $link = $resource.RelPermalink }}
{{ else }}
{{ $link = $link | relURL }}
{{ end }}
{{ else if in (slice "http" "https") $scheme }}
{{ $target = "target=\"_blank\" rel=\"noopener\"" }}
{{ end }}
<a class="hb-attachment-link {{ if $is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ $link | safeURL }}" {{ $target | safeHTMLAttr }}>
{{ partial "functions/get_icon" (dict "name" "link" "attributes" "style=\"height: 1em\" class='inline-block'") }}
{{ if .icon }}<i class="{{ $pack }} {{ $pack_prefix }}-{{ .icon }} {{if .name}}mr-1{{end}}"></i>{{end}}
{{- with .name }}{{ . | safeHTML }}{{ end -}}
</a>
{{ end }}
12 changes: 12 additions & 0 deletions modules/blox-tailwind/layouts/partials/page_links_div.html
@@ -0,0 +1,12 @@
{{/* Div wrapper around page links. */}}
{{/* The wrapper is hidden when the page has no link buttons. */}}

{{ $has_attachments := partial "functions/has_attachments" . }}
{{ if $has_attachments | or .Params.external_link }}
<div class="">
{{ 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" . "is_list" 0) }}
</div>
{{ end }}

0 comments on commit 75a4222

Please sign in to comment.