Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter data #181

Merged
merged 13 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
300 changes: 155 additions & 145 deletions .github/workflows/process_data.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ lang: de
#
# Set the metadata for your collection (the name of the CSV file in your _data directory that describes the objects in your collection)
# Use the filename of your CSV **without** the ".csv" extension! E.g. _data/demo-metadata.csv --> "demo-metadata"
metadata: sgb-metadata
metadata: sgb-metadata-csv
metadata-json: sgb-metadata-json
maehr marked this conversation as resolved.
Show resolved Hide resolved
# page generation settings [optional!]
# [optional: only used if you need to tweak CB defaults or generate from more than one data file]
# page_gen:
Expand Down
4 changes: 1 addition & 3 deletions _data/config-metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ field,display_name,browse_link,external_link,dc_map,schema_map
objectid,Identifikator,,,DCTERMS.identifier,identifier
title,Titel,,,DCTERMS.title,headline
description,Beschreibung,,,DCTERMS.description,description
relation,Verwandte Ressourcen,,true,DCTERMS.relation,relation
subject,Thema,true,,DCTERMS.subject,keywords
era,Epoche,true,,DCTERMS.temporal,
isPartOf,Gehört zu,,true,DCTERMS.isPartOf,isPartOf
Expand All @@ -15,6 +16,3 @@ extent,Auflösung,,,DCTERMS.extent,
language,Sprache,true,,DCTERMS.language,inLanguage
rights,Rechte,,,DCTERMS.rights,usageInfo
license,Lizenz,,true,DCTERMS.license,license
relation,Verwandte Ressourcen,,true,DCTERMS.relation,relation


4 changes: 2 additions & 2 deletions _data/theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ year-nav-increment: 50 # set increments to auto gen nav years
#
# add metadata fields for export in data downloads (tip: paste in first row of csv)
# comma delimited list, reference url is automatic
metadata-export-fields: "title,creator,date,description,subject,source,identifier,type,format,language,rights,rightsstatement"
metadata-export-fields: "objectid,parentid,title,description,relation,subject,era,isPartOf,creator,publisher,source,date,type,format,extent,language,rights,license"
# generate a facets list for given fields, comma delimited
metadata-facets-fields: "subject,creator,format"
metadata-facets-fields: "subject,creator,publisher,type,format,language,license"

##########
# Compound Objects
Expand Down
57 changes: 19 additions & 38 deletions _includes/js/browse-js.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,55 +84,36 @@
}

/* filter items function */
function filterItems(arr,q) {
// show loading icon
function filterItems(arr, q) {
// Show loading icon
loadingIcon.classList.remove("d-none");
// dont filter if no q
if (q=="") {
var filteredItems = arr;
} else {
q = q.trim().toUpperCase();
// js indexOf filter
var filteredItems = [];
for (var i = 0, len = arr.length; i < len; i++) {
var val = "";
for (var k in arr[i]) { val += arr[i][k] + " "; }
if(val.toUpperCase().indexOf(q) != -1){
filteredItems.push(arr[i]);
}
}
}
// add number
document.querySelector("#numberOf").innerHTML = filteredItems.length + " / {{ items | size }}";

// add stuff, make cards first in giant var, then add all at once to speed things up
var cards = "";
for (var i = 0, len = filteredItems.length; i < len; i++) {
cards += makeCard(filteredItems[i]);
}

// Trim and convert query to uppercase
const query = q.trim().toUpperCase();

// Filter items based on query
const filteredItems = query === "" ? arr : arr.filter(item => {
const itemValues = Object.values(item).join(" ").toUpperCase();
return itemValues.includes(query);
});

// Update number of filtered items
document.querySelector("#numberOf").innerHTML = `${filteredItems.length} / {{ items | size }}`;

// Generate and display cards for filtered items
const cards = filteredItems.map(makeCard).join("");
browseItemsDiv.innerHTML = cards;

// finish
// Finish
filterTextBox.focus();
loadingIcon.classList.add("d-none");
};

/* 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;
}

/* init browse page */

/* randomize items once at page load */
shuffle(items);
items = items.sort(() => Math.random() - 0.5);
maehr marked this conversation as resolved.
Show resolved Hide resolved

/* set some elements */
var loadingIcon = document.querySelector("#loadingIcon");
Expand Down
2 changes: 1 addition & 1 deletion assets/data/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
{%- assign items = site.data[site.metadata] | where_exp: 'item','item.objectid' -%}
{%- assign fields = site.data.theme.metadata-export-fields | split: "," -%}
{{ fields | join: "," }},object_thumb,object_location,reference_url
{% for item in items %}{% for f in fields %}"{{ item[f] | escape }}",{% endfor %}"{{ item.image_thumb | absolute_url }}","{{ item.object_location | absolute_url }}",{{ '/items/' | relative_url }}{% if item.parentid %}{{ item.parentid }}.html#{{ item.objectid }}{% else %}{{ item.objectid }}.html{% endif %}
{% for item in items %}{% for f in fields %}"{{ item[f] | escape }}",{% endfor %}"{{ item.image_thumb | absolute_url }}","{{ item.object_location | absolute_url }}",{{ '/items/' | absolute_url }}{% if item.parentid %}{{ item.parentid }}.html#{{ item.objectid }}{% else %}{{ item.objectid }}.html{% endif %}
{% endfor %}
6 changes: 3 additions & 3 deletions assets/data/metadata.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
# metadata for json export
---
{%- assign items = site.data[site.metadata] | where_exp: 'item','item.objectid' -%}
{%- assign items = site.data[site.metadata-json] -%}
{%- assign fields = site.data.theme.metadata-export-fields | split: "," -%}
{ "objects": [
{%- for item in items -%}
{
{% for f in fields %}{% if item[f] %}{{ f | jsonify }}: {{ item[f] | jsonify }},{% endif %}
{% endfor %}{% if item.image_thumb %}"object_thumb": "{{ item.image_thumb | absolute_url }}",{% endif %}
"object_location": "{{ item.object_location | absolute_url }}",
"reference_url": "{{ '/items/' | relative_url }}{% if item.parentid %}{{ item.parentid }}.html#{{ item.objectid }}{% else %}{{ item.objectid }}.html{% endif %}"
"reference_url": "{{ '/items/' | absolute_url }}{% if item.parentid.size > 0 %}{{ item.parentid }}.html#{{ item.objectid }}{% else %}{{ item.objectid }}.html{% endif %}"
}{% unless forloop.last %},{% endunless %}
{% endfor %}
] }
] }
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"scripts": {
"check": "prettier --check '**/*.{js,css,md,html}'",
"format": "prettier --write '**/*.{js,css,md,html}'"
"format": "prettier --write '**/*.{js,css,md,html}'",
"clean": "rm _data/sgb-metadata-* && find objects -type f ! -name 'README.md' -delete",
maehr marked this conversation as resolved.
Show resolved Hide resolved
"populate": "uv run .github/workflows/process_data.py"
},
"dependencies": {
"@shopify/prettier-plugin-liquid": "^1.5.2",
Expand Down