Files
bqkc/_includes/js/cloud-js.html
Nasir Anthony Montalvo 16adda8c47 Update documentation and permalinks for consistency and clarity
- Changed references in markup.md to update "data.html" to "data/" for clarity.
- Updated metadata.md to correct the link to the general documentation.
- Modified navbar.md to ensure stub values match the new permalink structure.
- Adjusted tables.md to reflect the new permalink for the table visualization page.
- Updated about.md to change the permalink from "/about.html" to "/about/" and revised content for clarity and impact.
- Changed browse.md permalink from "/browse.html" to "/browse/" for consistency.
- Added copyright.md page with copyright information and terms of use.
- Updated data.md to change permalink from "/data.html" to "/data/" and added introductory content.
- Created donate.md page to facilitate donations and acknowledge supporters.
- Updated locations.md permalink from "/locations.html" to "/locations/" for consistency.
- Changed map.md permalink from "/map.html" to "/map/" for uniformity.
- Added erasure.md page discussing the historical context of Black queer Kansas Citians.
- Updated out-there.md to correct the link to Lea Hopkins' interview.
- Changed subjects.md permalink from "/subjects.html" to "/subjects/" for consistency.
- Updated timeline.md permalink from "/timeline.html" to "/timeline/" for uniformity.
2026-01-15 00:45:32 -06:00

69 lines
2.9 KiB
HTML

{%- comment -%}
Generates a subject cloud using js to process the terms for display on "cloud" 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 cloud_id = include.id | default: "cloud" -%}
{%- assign cloud-fields = include.fields | split: ";" -%}
{%- comment -%} capture terms from all cloud fields {%- endcomment -%}
{%- assign terms = "" -%}
{%- for c in cloud-fields -%}
{% assign new = items | map: c | compact | join: ";" | split: ";" %}
{% capture field_terms %}{% for n in new %}{{n}}~{{c}};{% endfor %}{% endcapture %}
{% assign terms = terms | append: ";" | append: field_terms %}
{%- endfor -%}
{%- comment -%} find unique terms and counts {%- endcomment -%}
{%- assign uniqTerms = terms | downcase | split: ";" | array_count_uniq | sort | where_exp: 't','t[1] >= termsMin' -%}
<script>
(function(){
/* subject terms + count */
var terms = [
{% for t in uniqTerms %}{% assign term_field = t[0] | split: "~" %}[{{ term_field[0] | jsonify }}, {{ t[1] | jsonify }},{{term_field[1] | jsonify}}]{% unless forloop.last %}, {% endunless %}{% endfor %}
];
{% if include.stopwords %}/* apply stopwords */
var stopWords = {{ include.stopwords | downcase | split: ';' | jsonify }};
terms = terms.filter(function(a) { return stopWords.indexOf(a[0]) < 0;});{% endif %}
/* calculate max size */
var counts = terms.map(function(obj){ return obj[1]; });
var countMax = counts.reduce(function(a, b) { return Math.max(a, b); });
var cloud = document.getElementById("{{ cloud_id }}");
{% if include.shuffle == true %}
/* Fisher-Yates shuffle https://bost.ocks.org/mike/shuffle/ */
function shuffle(array) {
var m = array.length, t, i;
while (m) {
i = Math.floor(Math.random() * m--);
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
{% endif %}
function mapSize(x) { return Math.round(x * 9 / countMax + 1); }
/* create cloud */
function makeGrid(array) {
var i, size;
var items = "";
{% if include.shuffle == true %}shuffle(array);{% endif %}
for (let i = 0; i < array.length; i++) {
size = mapSize(array[i][1]);
items += '<a class="btn btn-{{ include.button | default: "outline-primary" }} m-2 tagcloud' + size + '" href="{{ "/browse/" | relative_url }}#' + array[i][2] + ':' + encodeURIComponent(array[i][0]) + '" >' + array[i][0] + '</a>';
}
cloud.innerHTML = items;
}
makeGrid(terms);
})();
</script>