diff --git a/modules/blox/blox/collection/block.html b/modules/blox/blox/collection/block.html index 79fa5e2d..08b6d8df 100644 --- a/modules/blox/blox/collection/block.html +++ b/modules/blox/blox/collection/block.html @@ -5,14 +5,21 @@ {{/* Initialise */}} {{ $page := .wcPage }} {{ $block := .wcBlock }} -{{ $view := $block.design.view | default "card" }} +{{ $content := $block.content }} +{{ if not (reflect.IsMap $content) }}{{ $content = dict }}{{ end }} +{{ $design := $block.design }} +{{ if not (reflect.IsMap $design) }}{{ $design = dict }}{{ end }} -{{ $items_offset := $block.content.offset | default 0 }} -{{ $items_count := $block.content.count }} +{{ $view := "card" }} +{{ $view_raw := index $design "view" }} +{{ if eq (printf "%T" $view_raw) "string" }} + {{ $view = lower (strings.TrimSpace $view_raw) }} +{{ end }} + +{{ $items_offset := partial "functions/coerce_int" (dict "value" (index $content "offset") "default" 0 "min" 0) }} +{{ $items_count := partial "functions/coerce_int" (dict "value" (index $content "count") "default" 5 "min" 0) }} {{ if eq $items_count 0 }} {{ $items_count = 65535 }} -{{ else }} - {{ $items_count = $items_count | default 5 }} {{ end }} {{/* Query */}} @@ -20,22 +27,78 @@ {{ $archive_page := "" }} {{/* Filters */}} -{{ $kinds := $block.content.filters.kinds | default (slice "page") }} +{{ $filters := index $content "filters" }} +{{ if not (reflect.IsMap $filters) }}{{ $filters = dict }}{{ end }} + +{{ $kinds := slice }} +{{ $kinds_raw := index $filters "kinds" }} +{{ if reflect.IsSlice $kinds_raw }} + {{ range $kinds_raw }} + {{ $kind := strings.TrimSpace (printf "%v" .) }} + {{ if $kind }} + {{ $kinds = $kinds | append $kind }} + {{ end }} + {{ end }} +{{ else if eq (printf "%T" $kinds_raw) "string" }} + {{ $kind := strings.TrimSpace $kinds_raw }} + {{ if $kind }} + {{ $kinds = slice $kind }} + {{ end }} +{{ end }} +{{ if eq (len $kinds) 0 }} + {{ $kinds = slice "page" }} +{{ end }} {{ $query = where $query "Kind" "in" $kinds }} -{{ if $block.content.page_type }} - {{ $query = where $query "Type" $block.content.page_type }} - {{ $archive_page = site.GetPage "Section" $block.content.page_type }} +{{ $page_type := "" }} +{{ $page_type_raw := index $content "page_type" }} +{{ if eq (printf "%T" $page_type_raw) "string" }} + {{ $page_type = strings.TrimSpace $page_type_raw }} {{ end }} -{{ if $block.content.filters.folders }} - {{ $folders := $block.content.filters.folders }} +{{ if $page_type }} + {{ $query = where $query "Type" $page_type }} + {{ $archive_page = site.GetPage "Section" $page_type }} +{{ end }} + +{{ $folders_raw := index $filters "folders" }} +{{ $folders := slice }} +{{ if reflect.IsSlice $folders_raw }} + {{ range $folders_raw }} + {{ $folder := strings.TrimSpace (printf "%v" .) }} + {{ if $folder }} + {{ $folders = $folders | append $folder }} + {{ end }} + {{ end }} +{{ else if eq (printf "%T" $folders_raw) "string" }} + {{ $folder := strings.TrimSpace $folders_raw }} + {{ if $folder }} + {{ $folders = slice $folder }} + {{ end }} +{{ end }} +{{ if gt (len $folders) 0 }} {{ $query = where $query "Section" "in" $folders }} - {{/* Init archive page to main folder */}} - {{ $main_folder := index $folders 0 }} - {{ $archive_page = site.GetPage "Section" $main_folder }} + {{ $main_folder := strings.TrimSpace (printf "%v" (index $folders 0)) }} + {{ if $main_folder }} + {{ $archive_page = site.GetPage "Section" $main_folder }} + {{ end }} {{ end }} -{{ if $block.content.filters.tags }} - {{ $tags := $block.content.filters.tags }} + +{{ $tags_raw := index $filters "tags" }} +{{ $tags := slice }} +{{ if reflect.IsSlice $tags_raw }} + {{ range $tags_raw }} + {{ $tag := strings.TrimSpace (printf "%v" .) }} + {{ if $tag }} + {{ $tags = $tags | append $tag }} + {{ end }} + {{ end }} +{{ else if eq (printf "%T" $tags_raw) "string" }} + {{ $tag := strings.TrimSpace $tags_raw }} + {{ if $tag }} + {{ $tags = slice $tag }} + {{ end }} +{{ end }} +{{ if gt (len $tags) 0 }} {{ $selected := slice }} {{ range $tags }} {{ $tag_page := site.GetPage (printf "tags/%s" (urlize .)) }} @@ -45,47 +108,110 @@ {{ end }} {{ if gt (len $selected) 0 }} {{ $query = $query | intersect $selected }} - {{ $archive_page = site.GetPage (printf "tags/%s" (urlize (index $tags 0))) }} + {{ $first_tag := index $tags 0 }} + {{ $archive_page = site.GetPage (printf "tags/%s" (urlize $first_tag)) }} {{ end }} {{ end }} -{{ if $block.content.filters.tag }} - {{ $archive_page = site.GetPage (printf "tags/%s" (urlize $block.content.filters.tag)) }} - {{ $query = $query | intersect $archive_page.Pages }} + +{{ $tag := "" }} +{{ $tag_raw := index $filters "tag" }} +{{ if eq (printf "%T" $tag_raw) "string" }} + {{ $tag = strings.TrimSpace $tag_raw }} {{ end }} -{{ if $block.content.filters.category }} - {{ $archive_page = site.GetPage (printf "categories/%s" (urlize $block.content.filters.category)) }} - {{ $query = $query | intersect $archive_page.Pages }} +{{ if $tag }} + {{ with site.GetPage (printf "tags/%s" (urlize $tag)) }} + {{ $archive_page = . }} + {{ $query = $query | intersect .Pages }} + {{ end }} {{ 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 }} + +{{ $category := "" }} +{{ $category_raw := index $filters "category" }} +{{ if eq (printf "%T" $category_raw) "string" }} + {{ $category = strings.TrimSpace $category_raw }} {{ end }} -{{ if $block.content.filters.exclude_publication_type }} - {{ $query = $query | complement (site.GetPage (printf "publication_types/%s" $block.content.filters.exclude_publication_type)).Pages }} +{{ if $category }} + {{ with site.GetPage (printf "categories/%s" (urlize $category)) }} + {{ $archive_page = . }} + {{ $query = $query | intersect .Pages }} + {{ end }} {{ end }} -{{ if $block.content.filters.author }} - {{ $archive_page = site.GetPage (printf "authors/%s" (urlize $block.content.filters.author)) }} - {{ $query = $query | intersect $archive_page.Pages }} + +{{ $publication_type := "" }} +{{ $publication_type_raw := index $filters "publication_type" }} +{{ if eq (printf "%T" $publication_type_raw) "string" }} + {{ $publication_type = strings.TrimSpace $publication_type_raw }} {{ end }} -{{ if $block.content.filters.featured_only }} +{{ if $publication_type }} + {{ with site.GetPage (printf "publication_types/%s" $publication_type) }} + {{ $archive_page = . }} + {{ $query = $query | intersect .Pages }} + {{ end }} +{{ end }} + +{{ $exclude_publication_type := "" }} +{{ $exclude_publication_type_raw := index $filters "exclude_publication_type" }} +{{ if eq (printf "%T" $exclude_publication_type_raw) "string" }} + {{ $exclude_publication_type = strings.TrimSpace $exclude_publication_type_raw }} +{{ end }} +{{ if $exclude_publication_type }} + {{ with site.GetPage (printf "publication_types/%s" $exclude_publication_type) }} + {{ $query = $query | complement .Pages }} + {{ end }} +{{ end }} + +{{ $author_filter := "" }} +{{ $author_filter_raw := index $filters "author" }} +{{ if eq (printf "%T" $author_filter_raw) "string" }} + {{ $author_filter = strings.TrimSpace $author_filter_raw }} +{{ end }} +{{ if $author_filter }} + {{ with site.GetPage (printf "authors/%s" (urlize $author_filter)) }} + {{ $archive_page = . }} + {{ $query = $query | intersect .Pages }} + {{ end }} +{{ end }} + +{{ $featured_only := partial "functions/coerce_bool" (dict "value" (index $filters "featured_only") "default" false) }} +{{ if $featured_only }} {{ $query = where $query "Params.featured" "==" true }} {{ end }} -{{ if $block.content.filters.exclude_featured }} +{{ $exclude_featured := partial "functions/coerce_bool" (dict "value" (index $filters "exclude_featured") "default" false) }} +{{ if $exclude_featured }} {{ $query = where $query "Params.featured" "!=" true }} {{ end }} -{{ if $block.content.filters.exclude_past }} +{{ $exclude_past := partial "functions/coerce_bool" (dict "value" (index $filters "exclude_past") "default" false) }} +{{ if $exclude_past }} {{ $query = where $query "Date" ">=" now }} {{ end }} -{{ if $block.content.filters.exclude_future }} +{{ $exclude_future := partial "functions/coerce_bool" (dict "value" (index $filters "exclude_future") "default" false) }} +{{ if $exclude_future }} {{ $query = where $query "Date" "<" now }} {{ end }} {{ $count := len $query }} {{/* Sort */}} -{{ $sort_by := $block.content.sort_by | default "Date" }} +{{ $sort_by := "Date" }} +{{ $sort_by_raw := index $content "sort_by" }} +{{ if eq (printf "%T" $sort_by_raw) "string" }} + {{ $sort_by_raw = strings.TrimSpace $sort_by_raw }} + {{ if ne $sort_by_raw "" }} + {{ $sort_by = $sort_by_raw }} + {{ end }} +{{ end }} {{ $sort_by = partial "functions/get_sort_by_parameter" $sort_by }} -{{ $sort_ascending := $block.content.sort_ascending | default (eq $block.content.order "asc") | default false }} +{{ $sort_ascending := false }} +{{ if isset $content "sort_ascending" }} + {{ $sort_ascending = partial "functions/coerce_bool" (dict "value" (index $content "sort_ascending") "default" false) }} +{{ else }} + {{ $order_raw := index $content "order" }} + {{ if eq (printf "%T" $order_raw) "string" }} + {{ if eq (lower (strings.TrimSpace $order_raw)) "asc" }} + {{ $sort_ascending = true }} + {{ end }} + {{ end }} +{{ end }} {{ $sort_order := cond $sort_ascending "asc" "desc" }} {{ $query = sort $query $sort_by $sort_order }} @@ -104,28 +230,32 @@ {{ end }} {{ end }} -{{ $columns := $block.design.columns | default "2" }} +{{ $columns := partial "functions/coerce_int" (dict "value" (index $design "columns") "default" 2 "min" 1 "max" 4) }} +{{ $title := "" }} +{{ with index $content "title" }}{{ $title = printf "%v" . | emojify | $page.RenderString }}{{ end }} +{{ $text := "" }} +{{ with index $content "text" }}{{ $text = printf "%v" . | emojify | $page.RenderString }}{{ end }} -{{ if $block.content.title }} +{{ if $title }}
{{ . | emojify | $page.RenderString }}
{{ end }} + {{ with $text }}{{ . }}
{{ end }}({{ . }})
- {{- end -}} + {{ end }} + {{ $role_text := "" }} {{ with $profile.role }} + {{ if eq (printf "%T" .) "string" }} + {{ $role_text = . }} + {{ end }} + {{ end }} + {{ with $role_text }}{{ . | markdownify | emojify }}
{{ end }} - {{ range $profile.affiliations }} -- {{ with .url }}{{ end }} - {{ .name }} - {{ if .url }}{{ end }} -
+ {{ $affiliations_raw := $profile.affiliations }} + {{ $affiliations := slice }} + {{ if reflect.IsSlice $affiliations_raw }} + {{ $affiliations = $affiliations_raw }} + {{ else if eq (printf "%T" $affiliations_raw) "string" }} + {{ $affiliations = slice $affiliations_raw }} + {{ end }} + {{ range $affiliations }} + {{ $aff_name := "" }} + {{ $aff_url := "" }} + {{ if reflect.IsMap . }} + {{ $nameRaw := index . "name" | default (index . "title") }} + {{ if ne $nameRaw nil }} + {{ $aff_name = printf "%v" $nameRaw }} + {{ end }} + {{ $urlRaw := index . "url" }} + {{ if eq (printf "%T" $urlRaw) "string" }} + {{ $aff_url = $urlRaw }} + {{ end }} + {{ else if eq (printf "%T" .) "string" }} + {{ $aff_name = . }} + {{ end }} + {{ $aff_name = strings.TrimSpace $aff_name }} + {{ $aff_url = strings.TrimSpace $aff_url }} + {{ if $aff_name }} ++ {{ if $aff_url }} + {{ $link := $aff_url }} + {{ $scheme := (urls.Parse $link).Scheme }} + {{ $target := "" }} + {{ if not $scheme }} + {{ if not (hasPrefix $link "#") }} + {{ $link = $link | relLangURL }} + {{ end }} + {{ if eq (path.Ext $link) ".pdf" }}{{ $target = "target=\"_blank\" rel=\"noopener\"" }}{{ end }} + {{ else if in (slice "http" "https") $scheme }} + {{ $target = "target=\"_blank\" rel=\"noopener\"" }} + {{ end }} + {{ $aff_name }} + {{ else }} + {{ $aff_name }} + {{ end }} +
+ {{ end }} {{ end }}{{ $degree }}
- {{ if .year }} -{{ .year }}
- {{ else if .start }} + {{ end }} + {{ if $year }} +{{ $year }}
+ {{ else if $start }}
- {{ .start }}
- {{ if .end }}
{{ .end }}{{ end }}
+ {{ $start }}
+ {{ if $end }}
{{ $end }}{{ end }}
{{ .institution }}
+ {{ if $institution }} +{{ $institution }}
+ {{ end }}{{ . }}
{{ end }} - {{ if and $show_organizations $profile.affiliations }} - {{ range first 1 $profile.affiliations }} -{{ .name }}
- {{ end }} + {{ if and $show_organizations $first_affiliation }} +{{ $first_affiliation }}
{{ end }}{{ . }}
{{ end }} - {{ if and $show_interests $profile.interests }} + {{ $interests_raw := $profile.interests }} + {{ $interests := slice }} + {{ if reflect.IsSlice $interests_raw }} + {{ $interests = $interests_raw }} + {{ else if eq (printf "%T" $interests_raw) "string" }} + {{ $interests = slice $interests_raw }} + {{ end }} + {{ if and $show_interests (gt (len $interests) 0) }}{{ . }}
{{ end }} - {{ if and $show_organizations $profile.affiliations }} - {{ range first 1 $profile.affiliations }} -{{ .name }}
+ {{ $roleText := "" }} + {{ with $profile.role }} + {{ if eq (printf "%T" .) "string" }} + {{ $roleText = . }} {{ end }} {{ end }} + {{ if and (not $roleText) $first_affiliation }} + {{ $roleText = $first_affiliation }} + {{ end }} + {{ with $roleText }}{{ . }}
{{ end }} + {{ if and $show_organizations $first_affiliation }} +{{ $first_affiliation }}
+ {{ end }}{{ . }}
{{ end }} - {{ if and $show_interests $profile.interests }} + + {{ $interests_raw := $profile.interests }} + {{ $interests := slice }} + {{ if reflect.IsSlice $interests_raw }} + {{ $interests = $interests_raw }} + {{ else if eq (printf "%T" $interests_raw) "string" }} + {{ $interests = slice $interests_raw }} + {{ end }} + {{ if and $show_interests (gt (len $interests) 0) }}