From 387fce0b6a1ddfdbcb097faf92dd4b7de9558d7d Mon Sep 17 00:00:00 2001 From: mtwente <127845092+mtwente@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:52:17 +0200 Subject: [PATCH 1/2] feat: add list view --- _includes/js/list-js.html | 87 +++++++++++++++++++++++++++++++++++++++ _layouts/list.html | 33 +++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 _includes/js/list-js.html create mode 100644 _layouts/list.html diff --git a/_includes/js/list-js.html b/_includes/js/list-js.html new file mode 100644 index 0000000..84a80cb --- /dev/null +++ b/_includes/js/list-js.html @@ -0,0 +1,87 @@ +{%- comment -%} + + Generates a list-group using js to process the terms for display on "list" layout. + Requires CB's array_count_uniq.rb plugin! + +{%- endcomment -%} +{% if site.data.theme.browse-child-objects == true %} +{%- assign items = site.data[site.metadata] | where_exp: 'item','item.objectid' -%} +{% else %} +{%- assign items = site.data[site.metadata] | where_exp: 'item','item.objectid and item.parentid == nil' -%} +{% endif %} +{%- assign termsMin = include.min | plus: 0 | default: 1 -%} +{%- assign list_id = include.id | default: "list-group" -%} +{%- assign list-fields = include.fields | split: ";" -%} + +{%- comment -%} capture terms from all list fields {%- endcomment -%} +{%- assign terms = "" -%} +{%- for c in list-fields -%} +{% assign new = items | map: c | join: ";" %} +{% assign terms = terms | append: ";" | append: new %} +{%- endfor -%} +{%- comment -%} find unique terms and counts {%- endcomment -%} +{%- assign uniqTerms = terms | split: ";" | array_count_uniq | sort | where_exp: 't','t[1] >= termsMin' -%} + + \ No newline at end of file diff --git a/_layouts/list.html b/_layouts/list.html new file mode 100644 index 0000000..0e5b51b --- /dev/null +++ b/_layouts/list.html @@ -0,0 +1,33 @@ +--- +layout: page +--- + +{{ content }} + + +{%- if page.cloud-fields == "site.data.theme.subjects-fields" -%} + {% assign fields = site.data.theme.subjects-fields %} + {% assign min = site.data.theme.subjects-min | default: 1 %} + {% assign stopwords = site.data.theme.subjects-stopwords %} +{%- elsif page.cloud-fields == "site.data.theme.locations-fields" -%} + {% assign fields = site.data.theme.locations-fields %} + {% assign min = site.data.theme.locations-min | default: 1 %} + {% assign stopwords = site.data.theme.locations-stopwords %} +{%- else -%} + {% assign fields = page.cloud-fields | default: "subjects" %} + {% assign min = page.cloud-min | default: 1 %} + {% assign stopwords = page.cloud-stopwords %} +{%- endif -%} + +{% assign list_id = "list-div-" | append: fields | slugify %} +