feat(blocks-v2): add Collection, Contact, Tag Cloud

This commit is contained in:
George Cushen committed 2022-10-25 22:48:55 +01:00
1 parent c51be55f93
commit 5dcefaa0c5
5 files changed
+349 -11

No files matched your search

+4 -3
View File
@@ -18,10 +18,11 @@
{{/* Generate homepage. */}}
{{ if eq .Type "book" }}
{{ partial "book_layout.html" . }}
{{ else if eq .Type "widget_page" }}
{{ partial "widget_page.html" . }}
{{ else }}
{{ else if eq .Type "landing" }}
{{ partial "landing_page.html" . }}
{{ else }}
{{/* If no homepage file is present, fallback to legacy widget page */}}
{{ partial "widget_page.html" . }}
{{ end }}
{{- end -}}
@@ -0,0 +1,121 @@
{{/* Wowchemy Blocks: Collection */}}
{{/* Documentation: https://wowchemy.com/blocks/ */}}
{{/* License: https://github.com/wowchemy/wowchemy-hugo-themes/blob/main/LICENSE.md */}}
{{/* Initialise */}}
{{ $page := .wcPage }}
{{ $block := .wcBlock }}
{{ $items_offset := $block.content.offset | default 0 }}
{{ $items_count := $block.content.count }}
{{ if eq $items_count 0 }}
{{ $items_count = 65535 }}
{{ else }}
{{ $items_count = $items_count | default 5 }}
{{ end }}
{{/* Query */}}
{{ $query := site.RegularPages }}
{{ $archive_page := "" }}
{{/* Filters */}}
{{ if $block.content.page_type }}
{{ $query = where $query "Type" $block.content.page_type }}
{{ $archive_page = site.GetPage "Section" $block.content.page_type }}
{{ end }}
{{ if $block.content.filters.folders }}
{{ $folders := $block.content.filters.folders }}
{{ $query = where $query "Section" "in" $folders }}
{{/* Init archive page to main folder */}}
{{ $main_folder := index $folders 0 }}
{{ $archive_page = site.GetPage "Section" $main_folder }}
{{ end }}
{{ if $block.content.filters.tag }}
{{ $archive_page = site.GetPage (printf "tags/%s" (urlize $block.content.filters.tag)) }}
{{ $query = $query | intersect $archive_page.Pages }}
{{ end }}
{{ if $block.content.filters.category }}
{{ $archive_page = site.GetPage (printf "categories/%s" (urlize $block.content.filters.category)) }}
{{ $query = $query | intersect $archive_page.Pages }}
{{ end }}
{{ if $block.content.filters.publication_type }}
{{ $archive_page = site.GetPage (printf "publication_types/%s" $block.content.filters.publication_type) }}
{{ $query = $query | intersect $archive_page.Pages }}
{{ end }}
{{ if $block.content.filters.author }}
{{ $archive_page = site.GetPage (printf "authors/%s" (urlize $block.content.filters.author)) }}
{{ $query = $query | intersect $archive_page.Pages }}
{{ end }}
{{ if $block.content.filters.featured_only }}
{{ $query = where $query "Params.featured" "==" true }}
{{ end }}
{{ if $block.content.filters.exclude_featured }}
{{ $query = where $query "Params.featured" "!=" true }}
{{ end }}
{{ if $block.content.filters.exclude_past }}
{{ $query = where $query "Date" ">=" now }}
{{ end }}
{{ if $block.content.filters.exclude_future }}
{{ $query = where $query "Date" "<" now }}
{{ end }}
{{ $count := len $query }}
{{/* Sort */}}
{{ $sort_by := $block.content.sort_by | default "Date" }}
{{ $sort_ascending := $block.content.sort_ascending | default (eq $block.content.order "asc") | default false }}
{{ $sort_order := cond $sort_ascending "asc" "desc" }}
{{ $query = sort $query $sort_by $sort_order }}
{{/* Offset and Limit */}}
{{ if gt $items_offset 0 }}
{{ $query = first $items_count (after $items_offset $query) }}
{{ else }}
{{ $query = first $items_count $query }}
{{ end }}
{{ $columns := $block.design.columns | default "2" }}
<div class="col-12 {{if eq $columns "2"}}col-lg-8{{end}}">
{{ with $block.content.text }}{{ . }}{{ end }}
{{ range $index, $item := $query }}
{{ partial "functions/render_view" (dict "page" $block "item" . "view" ($block.design.view | default "compact") "index" $index) }}
{{end}}
{{/* Archive link */}}
{{ $show_archive_link := $block.content.archive.enable | default (gt $count $items_count) }}
{{ if $show_archive_link | and $archive_page }}
{{ $archive_link := "" }}
{{ if $block.content.archive.link }}
{{ $archive_link = $block.content.archive.link | relLangURL }}
{{ else }}
{{ $archive_link = $archive_page.RelPermalink }}
{{ end }}
{{/* Localisation */}}
{{ $items_type := $archive_page.Type }}
{{ $i18n := "" }}
{{ if eq $items_type "post" }}
{{ $i18n = "more_posts" }}
{{ else if eq $items_type "event" }}
{{ $i18n = "more_talks" }}
{{ else if eq $items_type "publication" }}
{{ $i18n = "more_publications" }}
{{ else }}
{{ $i18n = "more_pages" }}
{{ end }}
{{ $archive_text := $block.content.archive.text | default (i18n $i18n) | default "See all" }}
<div class="see-all">
<a href="{{ $archive_link }}">
{{ $archive_text | emojify }}
<i class="fas fa-angle-right"></i>
</a>
</div>
{{ end }}
</div>
@@ -0,0 +1,169 @@
{{/* Wowchemy Blocks: Contact */}}
{{/* Documentation: https://wowchemy.com/blocks/ */}}
{{/* License: https://github.com/wowchemy/wowchemy-hugo-themes/blob/main/LICENSE.md */}}
{{/* Initialise */}}
{{ $page := .wcPage }}
{{ $block := .wcBlock }}
{{ $autolink := default true $block.content.autolink }}
{{ $data := $block.content }}
{{ $form_provider := lower $block.content.form.provider | default "" }}
{{ $use_netlify_form := eq $form_provider "netlify" }}
{{ $use_formspree_form := eq $form_provider "formspree" }}
{{ $use_form := or $use_netlify_form $use_formspree_form }}
{{ $use_netlify_captcha := $block.content.form.netlify.captcha | default true }}
{{ $use_formspree_captcha := $block.content.form.formspree.captcha | default false }}
{{ $columns := $block.design.columns | default "2" }}
{{ if and $use_formspree_form $use_formspree_captcha }}
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
{{ end }}
<div class="col-12 {{if eq $columns "2"}}col-lg-8{{end}}">
{{ with $block.content.text }}{{ . }}{{ end }}
{{ if $use_form }}
{{ $post_action := "" }}
{{ if $use_netlify_form }}
{{ $post_action = "netlify" }}
{{ else if $use_formspree_form }}
{{ if not $block.content.form.formspree.id }}
{{ errorf "You have chosen to use Formspree as the provider for the contact form. Please set your Formspree Form ID in the Contact widget or disable the form.\nDocumentation: https://wowchemy.com/docs/widget/contact/" }}
{{ end }}
{{ if and $use_formspree_captcha (not $block.content.form.formspree.captcha_key) }}
{{ errorf "You have chosen to use reCAPTCHA for Formspree. Please set your Formspree CAPTCHA KEY in the Contact widget or disable reCAPTCHA.\nDocumentation: https://help.formspree.io/hc/en-us/articles/360022811154" }}
{{ end }}
{{ $post_action = printf "action=\"https://formspree.io/f/%s\"" $block.content.form.formspree.id }}
{{ end }}
<div class="mb-3">
<form name="contact" method="POST" {{ $post_action | safeHTMLAttr }} {{ if $use_netlify_form }}netlify-honeypot="_gotcha"{{ end }} {{ if $use_netlify_captcha }}data-netlify-recaptcha="true"{{ end }} {{ with $block.content.form.netlify.success_url }}action="{{ . | relLangURL }}"{{ end }}>
<div class="form-group form-inline">
<label class="sr-only" for="inputName">{{ i18n "contact_name" }}</label>
<input type="text" name="name" class="form-control w-100" id="inputName" placeholder="{{ i18n "contact_name" | default "Name" }}" required>
</div>
<div class="form-group form-inline">
<label class="sr-only" for="inputEmail">{{ i18n "contact_email" }}</label>
<input type="email" name="email" class="form-control w-100" id="inputEmail" placeholder="{{ i18n "contact_email" | default "Email" }}" required>
</div>
<div class="form-group">
<label class="sr-only" for="inputMessage">{{ i18n "contact_message" }}</label>
<textarea name="message" class="form-control" id="inputMessage" rows="5" placeholder="{{ i18n "contact_message" | default "Message" }}" required></textarea>
</div>
{{ if $block.content.form.netlify.attachments }}
<div class="form-group form-inline">
<label class="sr-only" for="fileUpload">{{ i18n "contact_attachment" }}</label>
<input type="file" name="file" class="form-control w-100" id="fileUpload" placeholder="{{ i18n "contact_attachment" | default "Attach file" }}">
</div>
{{ end }}
<div class="d-none">
<label>Do not fill this field unless you are a bot: <input name="_gotcha"></label>
</div>
{{ if and $use_netlify_form $use_netlify_captcha }}
<div class="form-group" data-netlify-recaptcha="true"></div>
{{ else if and $use_formspree_form $use_formspree_captcha }}
<div class="g-recaptcha" data-sitekey="{{ $block.content.form.formspree.captcha_key }}"></div>
</br>
{{ end }}
<button type="submit" class="btn btn-primary px-3 py-2 w-100">{{ i18n "contact_send" | default "Send" }}</button>
</form>
</div>
{{ end }}
<ul class="fa-ul">
{{ if $data.email }}
<li>
<i class="fa-li fas fa-envelope fa-2x" aria-hidden="true"></i>
<span id="person-email">
{{- if $autolink }}<a href="mailto:{{ $data.email }}">{{ $data.email }}</a>{{ else }}{{ $data.email }}{{ end -}}
</span>
</li>
{{ end }}
{{ with $data.phone }}
<li>
<i class="fa-li fas fa-phone fa-2x" aria-hidden="true"></i>
<span id="person-telephone">
{{- if $autolink }}<a href="tel:{{ . }}">{{ . }}</a>{{ else }}{{ . }}{{ end -}}
</span>
</li>
{{ end }}
{{ $addr_formatted := "" }}{{/* Scoping for maps. */}}
{{ if $data.address.street | or $data.address.city | or $data.address.region | or $data.address.postcode | or $data.address.country }}
{{ $addr_formatted = partial "functions/get_address" (dict "root" . "address" $data.address) }}
<li>
<i class="fa-li fas fa-map-marker fa-2x" aria-hidden="true"></i>
<span id="person-address">{{$addr_formatted}}</span>
</li>
{{ end }}
{{ with $data.directions }}
<li>
<i class="fa-li fas fa-compass fa-2x" aria-hidden="true"></i>
<span>{{ . | markdownify | emojify }}</span>
</li>
{{ end }}
{{ with $data.office_hours }}
<li>
<i class="fa-li fas fa-clock fa-2x" aria-hidden="true"></i>
<span>
{{- if not (reflect.IsSlice .)}}{{/* Support legacy string format. */}}
{{- . | markdownify | emojify -}}
{{else}}
{{- delimit . "<br>" | markdownify | emojify -}}
{{end -}}
</span>
</li>
{{ end }}
{{ with $data.appointment_url }}
<li>
<i class="fa-li fas fa-calendar-check fa-2x" aria-hidden="true"></i>
<a href="{{ . }}" target="_blank" rel="noopener">{{ i18n "book_appointment" | default "Book an appointment" }}</a>
</li>
{{ end }}
{{/* Contact links. */}}
{{ range $data.contact_links }}
{{ $pack := or .icon_pack "fas" }}
{{ $pack_prefix := $pack }}
{{ if in (slice "fab" "fas" "far" "fal") $pack }}
{{ $pack_prefix = "fa" }}
{{ end }}
{{ $link := .link }}
{{ $scheme := (urls.Parse $link).Scheme }}
{{ $target := "" }}
{{ if not $scheme }}
{{ $link = .link | relLangURL }}
{{ else if in (slice "http" "https") $scheme }}
{{ $target = "target=\"_blank\" rel=\"noopener\"" }}
{{ end }}
<li>
<i class="fa-li {{ $pack }} {{ $pack_prefix }}-{{ .icon }} fa-2x" aria-hidden="true"></i>
<a href="{{ $link | safeURL }}" {{ $target | safeHTMLAttr }}>{{.name|markdownify|emojify|safeHTML}}</a>
</li>
{{ end }}
</ul>
{{ if and site.Params.features.map.provider $data.coordinates.latitude }}
<div class="d-none">
<input id="map-provider" value="{{ lower site.Params.features.map.provider }}">
<input id="map-lat" value="{{ $data.coordinates.latitude }}">
<input id="map-lng" value="{{ $data.coordinates.longitude }}">
<input id="map-dir" value="{{ $addr_formatted }}">
<input id="map-zoom" value="{{ site.Params.features.map.zoom | default "15" }}">
<input id="map-api-key" value="{{ site.Params.features.map.api_key }}">
</div>
<div id="map"></div>
{{ end }}
</div>
@@ -0,0 +1,47 @@
{{/* Wowchemy Blocks: Tag Cloud */}}
{{/* Documentation: https://wowchemy.com/blocks/ */}}
{{/* License: https://github.com/wowchemy/wowchemy-hugo-themes/blob/main/LICENSE.md */}}
{{/* Initialise */}}
{{ $page := .wcPage }}
{{ $block := .wcBlock }}
{{ $taxonomy := $block.content.taxonomy | default "tags" }}
{{ $fontSmall := $block.design.font_size_min | default 0.8 }}
{{ $fontBig := $block.design.font_size_max | default 2.5 }}
{{ $items_count := $block.content.count }}
{{ if eq $items_count 0 }}
{{ $items_count = 65535 }}
{{ else }}
{{ $items_count = $items_count | default 20 }}
{{ end }}
{{/* Query */}}
{{ $tags := first $items_count (index site.Taxonomies $taxonomy).ByCount }}
{{ $count := len $tags }}
{{ $columns := $block.design.columns | default "2" }}
<div class="col-12 {{if eq $columns "2"}}col-lg-8{{else}}text-center{{end}}">
{{ with $block.content.text }}{{ . | markdownify }}{{ end }}
{{ if ne $count 0 }}
{{ $fontDelta := sub $fontBig $fontSmall }}
{{/* Warning: Hugo's `Reverse` function appears to operate in-place, hence the order of performing $max/$min matters. */}}
{{ $max := add (len (index $tags 0).Pages) 1 }}
{{ $min := len (index ($tags).Reverse 0).Pages }}
{{ $delta := sub $max $min }}
{{ $fontStep := div $fontDelta $delta }}
<div class="tag-cloud">
{{ range $name, $term := (sort $tags ".Page.Title" "asc") }}
{{ $tagCount := len $term.Pages }}
{{ $weight := div (sub (math.Log $tagCount) (math.Log $min)) (sub (math.Log $max) (math.Log $min)) }}
{{ $fontSize := add $fontSmall (mul (sub $fontBig $fontSmall) $weight) }}
<a href="{{ .Page.RelPermalink }}" style="font-size:{{ $fontSize }}rem">{{ .Page.Title }}</a>
{{ end }}
</div>
{{ end }}
</div>
@@ -49,7 +49,7 @@
{{ end }}
{{ $style_bg = printf "%sbackground-image: url('%s');" $style_bg $bg_img.Permalink }}
{{ else }}
{{ errorf "Couldn't find `%s` in the `assets/media/` folder - please add it." $bg.image }}
{{ errorf "Couldn't find `%s` in the `assets/media/` folder - please add it." $bg.image.filename }}
{{ end }}
{{ with $bg.image.size }}
{{/* Allow sizes: actual, cover, and contain. */}}
@@ -81,7 +81,7 @@
{{ end }}
{{/* Fix Hugo's ContentBaseName returning wrong file base name when page section is within a bundle. */}}
{{ $hash_id := replace $block.File.ContentBaseName "index" (path.Base .File.Dir) }}
{{ $hash_id := $block.id | default (printf "section-%s" $block.block) }}
{{ $widget_args := dict "wcPage" $page "wcBlock" $block "wcIdentifier" $hash_id }}
{{ $css_classes := $block.design.css_class | default $block.Params.advanced.css_class | default "" }}
@@ -114,17 +114,17 @@
{{if $use_container}}<div class="container">{{end}}
{{if $use_cols}}
<div class="row {{if not $block.Title | or (eq $columns "1") }}justify-content-center{{end}}">
{{ if $block.Title }}
<div class="row {{if not $block.content.title | or (eq $columns "1") }}justify-content-center{{end}}">
{{ if $block.content.title }}
{{ if eq $columns "1" }}
<div class="section-heading col-12 mb-3 text-center">
{{ with $block.Title }}<h1 class="mb-0">{{ . | markdownify | emojify }}</h1>{{ end }}
{{ with $block.Params.subtitle }}<p class="mt-1">{{ . | markdownify | emojify }}</p>{{ end }}
{{ with $block.content.title }}<h1 class="mb-0">{{ . | markdownify | emojify }}</h1>{{ end }}
{{ with $block.content.subtitle }}<p class="mt-1">{{ . | markdownify | emojify }}</p>{{ end }}
</div>
{{else}}
<div class="section-heading col-12 col-lg-4 mb-3 mb-lg-0 d-flex flex-column align-items-center align-items-lg-start">
{{ with $block.Title }}<h1 class="mb-0">{{ . | markdownify | emojify }}</h1>{{ end }}
{{ with $block.Params.subtitle }}<p class="mt-1">{{ . | markdownify | emojify }}</p>{{ end }}
{{ with $block.content.title }}<h1 class="mb-0">{{ . | markdownify | emojify }}</h1>{{ end }}
{{ with $block.content.subtitle }}<p class="mt-1">{{ . | markdownify | emojify }}</p>{{ end }}
</div>
{{end}}
{{end}}