---
# find and count unique subjects
#
# Requires CB's array_count_uniq.rb plugin!
---
{%- if site.data.theme.locations-fields -%}
{%- assign items = site.data[site.metadata] | where_exp: 'item','item.objectid' -%}
{%- assign locations-fields = site.data.theme.locations-fields | split: ";" -%}
{%- assign places = "" -%}
{%- for c in locations-fields -%}
{% assign new = items | map: c | join: ";" %}
{% assign places = places | append: ";" | append: new %}
{%- endfor -%}
{%- assign uniqPlaces = places | downcase | split: ";" | array_count_uniq -%}
{ "locations": [
    {% for s in uniqPlaces %}{ "location" : {{ s[0] | jsonify }}, "count" : {{ s[1] | jsonify }}, "link" : {{ s[0] | url_param_escape | prepend: '/browse/#' | absolute_url | jsonify }} }{% unless forloop.last %},
    {% endunless %}{% endfor %}
]}{%- endif -%}