Skip to content

Commit 70e6a20

Browse files
committed
fix sets
1 parent ad7e479 commit 70e6a20

7 files changed

Lines changed: 75 additions & 87 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"private": true,
55
"scripts": {
66
"dev": "vite dev",
7-
"build": "vite build",
87
"preview": "vite preview",
9-
"deploy": "gh-pages -d build -t true",
8+
"build": "vite build && touch build/.nojekyll",
9+
"deploy": "gh-pages -d build --dotfiles",
1010
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
1111
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch",
1212
"lint": "prettier --plugin-search-dir . --check . && eslint .",

src/components/GraphSection.svelte

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,65 +33,49 @@
3333
}
3434
}
3535
36+
// Helper to normalize IDs
37+
function normalizeId(id) {
38+
return id
39+
.replace(/\/items\//g, '/resources/')
40+
.replace(/\/media\//g, '/resources/')
41+
.replace(/\/item_sets\//g, '/resources/');
42+
}
43+
3644
async function openNode(node, index) {
3745
resetScroll(index);
3846
loadingColumn = true;
3947
40-
// Remove all elements in $graphSteps after the given index
4148
$graphSteps.splice(index, $graphSteps.length - index);
4249
4350
let columnNodes = $graphSteps.map((obj) => obj.data).flat();
4451
45-
// const response = await fetch(node.target);
46-
// const data = await response.json();
47-
48-
const data = $db.find(
49-
(d) =>
50-
d['@id']
51-
.replace(/\/items\//, '/resources/')
52-
.replace(/\/media\//, '/resources/')
53-
.replace(/\/item_sets\//, '/resources/') ===
54-
node.target
55-
.replace(/\/items\//, '/resources/')
56-
.replace(/\/media\//, '/resources/')
57-
.replace(/\/item_sets\//, '/resources/')
58-
);
52+
const data = $db.find((d) => normalizeId(d['@id']) === normalizeId(node.target));
5953
6054
//Fetch the items in the set // just for omeka s
6155
if (data?.['o:items'] && $graphSteps.length == 1) {
6256
let setData = [];
6357
const items = data['o:items']['@id'];
64-
// const responseSet = await fetch(items);
65-
// const jsonSet = await responseSet.json();
66-
67-
// check this
68-
const jsonSet = $db.find(
69-
(d) =>
70-
d['@id']
71-
.replace(/\/items\//, '/resources/')
72-
.replace(/\/media\//, '/resources/')
73-
.replace(/\/item_sets\//, '/resources/') ===
74-
node.target
75-
.replace(/\/items\//, '/resources/')
76-
.replace(/\/media\//, '/resources/')
77-
.replace(/\/item_sets\//, '/resources/')
78-
);
79-
80-
jsonSet.forEach((item) => {
81-
setData.push(item);
82-
});
8358
84-
// omeka s
59+
// Use filter (returns array, even if 0 or 1 elements)
60+
const jsonSet = $db.filter((d) => normalizeId(d['@id']) === normalizeId(node.target));
61+
62+
// Only call forEach if array is non-empty
63+
if (Array.isArray(jsonSet) && jsonSet.length) {
64+
jsonSet.forEach((item) => {
65+
setData.push(item);
66+
});
67+
}
68+
8569
let setItems = setData.map((d) => {
8670
return {
8771
title: d[config.paths.title] || d.data?.['@id'],
8872
'@id': d['@id'],
89-
thumbnail_display_urls: d[config.paths.img[0]]?.[0]['@id'] || getNestedValue(d, config.paths.img.join('.'))
73+
thumbnail_display_urls:
74+
d[config.paths.img[0]]?.[0]?.['@id'] || getNestedValue(d, config.paths.img.join('.'))
9075
};
9176
});
9277
93-
// add the set to the data
94-
data.related = { ...setItems };
78+
data.related = setItems;
9579
}
9680
9781
selectedTriplets = await createTriplets([{ data }]);
@@ -103,7 +87,6 @@
10387
let newNodes = updateNodes([...defaultNodes, ...columnNodes], selectedTripletsData);
10488
let paginate = selectedTripletsData.slice(0, batchSize);
10589
106-
// Replace the element at the given index with the new data
10790
$graphSteps[index] = {
10891
id: node.target,
10992
data: selectedTripletsData.sort((a, b) => {
@@ -124,6 +107,10 @@
124107
$updatePosition = true;
125108
}
126109
110+
function getNestedValue(obj, path) {
111+
return path.split('.').reduce((o, key) => (o || {})[key], obj);
112+
}
113+
127114
function updateNodes(nodes, selectedNodes) {
128115
return selectedNodes.filter((selectedNode) => {
129116
return !nodes.some((node) => {

src/routes/texts/03_Fashion_costume_terminology_en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cover: "https://uclab.fh-potsdam.de/refa-catalog/files/large/0a1096efd3fcd71023f
1313
In the late 19th century, the publishing couple [Frieda](https://uclab.fh-potsdam.de/refa-catalog/api/resources/18762) (1840-1896) and [Franz von Lipperheide](https://uclab.fh-potsdam.de/refa-catalog/api/resources/9364) (1838-1906) compiled sources on the history and meaning of clothing and thus founded the *[Lipperheide Costume Library](https://uclab.fh-potsdam.de/refa-catalog/api/resources/18717)*. The classifications of *fashion*, *costume (dt. Kostüm)* and *regional dress (dt. Tracht)* used by them are accordingly shaped by the understanding of the time and differ from today's terminology. Thus, the term *costume research* has also changed in consequence and is now called *dress research*, *fashion research* or *vestimentary research*. Depending on the research discipline, the terms are used differently and describe a methodological approach.[^Cf. de Günther 2022, pp. 10-14, Kleiderwechsel 2002, pp. 8-13, Mentges 2015, p. 76, Merseburger 2016, p. 30 and Warschaw 2017.]
1414

1515
## Fashion
16-
The etymology of the word *fashion* is still subject to different interpretations today: The derivation from the Latin *Modus*, which changed into *mode* in the French language, is disputed. It is possible that two forms of usage prevailed at the end of the 16th century: the masculine grammatical form *mode* in the sense of moderation, rule and modus, and the grammatically feminine form of *mode*, which stood for contemporary clothing and lifestyle. In its further dissemination in Germany and Italy, it initially finds application in the *Alamodische Bilderbogen*, a courtly entertainment literature that became widespread in Germany after the Thirty Years' War. It is also mentioned around 1620 with the meaning "the custom and dress originating in France". This longing for the fashionable was caricatured in *[Alamodische Blätter](https://uclab.fh-potsdam.de/refa-catalog/api/resources/48313)*[^Cf. Ridikül! 2003, Wolter 2002 and Wolter 2012.]. Subsequently, the word *fashion* became naturalised as the concept of the new and of instantaneous taste.
16+
The etymology of the word *fashion* is still subject to different interpretations today: The derivation from the Latin *Modus*, which changed into *mode* in the French language, is disputed. It is possible that two forms of usage prevailed at the end of the 16th century: the masculine grammatical form *mode* in the sense of moderation, rule and modus, and the grammatically feminine form of *mode*, which stood for contemporary clothing and lifestyle. In its further dissemination in Germany and Italy, it initially finds application in the *Alamodische Bilderbogen*, a courtly entertainment literature that became widespread in Germany after the Thirty Years' War. It is also mentioned around 1620 with the meaning "the custom and dress originating in France". This longing for the fashionable was caricatured in [Alamodische Blätter](https://uclab.fh-potsdam.de/refa-catalog/api/resources/48313) [^Cf. Ridikül! 2003, Wolter 2002 and Wolter 2012.]. Subsequently, the word *fashion* became naturalised as the concept of the new and of instantaneous taste.
1717

1818
## Regional dress
1919
The dictionary by Jacob and Wilhelm Grimm describes the meaning of *[regional costume](http://www.woerterbuchnetz.de/DWB?lemma=tracht)* (dt. Tracht) as "to wear or to be worn". The term regional costume (*Tracht*) was first used in 1497 to describe that which is worn on the body and also the way in which it is worn. The term denotes the clothing of the urban and rural population, as well as the garment worn at work as well as the garments in different professions.[^Jacob and Wilhelm Grimm's definition is far-reaching: it also stands for clerical clothing and distinguishes itself from the term “uniform”, a loan word which has been attested since 1746. Tracht also denotes the distinctive clothing of the different classes. Similarly, Tracht stands for mask and masquerade costume. Finally, the dictionary entry notes that Tracht and Fashion are used synonymously. The entry distinguishes between “die kleidungsart allgemein ohne das Moment des zeitgemäszen“ and “zeitgemäsze kleidungsart, Mode, also tracht heiszt die dem frauenzimmer nach einer jedem Landesart gewöhnliche und übliche mode sich einkleiden und anzuputzt” - “the type of dress in general without the moment of the contemporary” and the “contemporary mode of dress, fashion, cf. tracht means the usual and customary fashion for women to dress according to each national style”. In a figurative sense, it also denotes the attitude, the habitus.]

src/setup.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"title": "ReFa Reader",
33
"api": "https://uclab.fh-potsdam.de/refa-catalog/api",
4-
"local": "db_min.json",
4+
"local": "db2.json",
55
"url": "",
66
"paths": {
77
"title": "o:title",

src/utils.js

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ export async function extractLinks(markdown, mdData) {
77

88
let match;
99
while ((match = regex.exec(markdown))) {
10-
if (match[2].includes('http') && !match[2].includes(config.url)) {
10+
if (
11+
typeof match[2] === 'string' &&
12+
match[2].includes('http') &&
13+
!match[2].includes(config.url)
14+
) {
1115
continue;
1216
} else {
1317
const label = match[3];
14-
const url = decodeURIComponent(match[2]);
15-
// const id = url.split("/")[1] || url.split("/")[0];
16-
// console.log(label, id, url)
18+
const url = decodeURIComponent(match[2] || '');
1719

1820
links.push({
1921
label,
@@ -29,7 +31,9 @@ export async function extractLinks(markdown, mdData) {
2931
let parseItems = [...getItemsFromDbById(allUrls, mdData, 'items')];
3032

3133
for (let i = 0; i < links.length; i++) {
32-
const link = links.find((d) => parseItems[i]?.['@id'].includes(d.id));
34+
const link = links.find(
35+
(d) => typeof parseItems[i]?.['@id'] === 'string' && parseItems[i]['@id'].includes(d.id)
36+
);
3337
const json = parseItems[i];
3438
if (link) {
3539
link.uniqueId = newUniqueId();
@@ -40,23 +44,23 @@ export async function extractLinks(markdown, mdData) {
4044
return links;
4145
}
4246

43-
// Accepts both full URLs and Omeka IDs
4447
function getItemsFromDbById(ids, db, type) {
4548
return db.filter((item) => {
4649
const itemId = item['@id'];
47-
// Check direct match
50+
4851
if (ids.includes(itemId)) return true;
4952

50-
// Try replacing /media/, /items/, /item_sets/ to /resources/
5153
const normalizedId = itemId
5254
?.replace(/\/items\//, '/resources/')
5355
?.replace(/\/media\//, '/resources/')
5456
?.replace(/\/item_sets\//, '/resources/');
5557
if (ids.includes(normalizedId)) return true;
5658

57-
// Try checking if any provided id matches after normalization
5859
return ids.some(
59-
(id) => id === itemId || id === normalizedId || itemId.endsWith('/' + id) // e.g. just the numeric part
60+
(id) =>
61+
id === itemId ||
62+
id === normalizedId ||
63+
(typeof itemId === 'string' && itemId.endsWith('/' + id))
6064
);
6165
});
6266
}
@@ -67,7 +71,8 @@ export async function createTriplets(data) {
6771
for (let i = 0; i < data.length; i++) {
6872
if (data[i].data) {
6973
let jsonLD = data[i].data;
70-
let set = data[i].set || null; // omeka-s
74+
let set = data[i].set || null;
75+
console.log('here', jsonLD);
7176
let triplets = parseJSONLD(jsonLD, set);
7277

7378
allTriplets = [...allTriplets, ...triplets];
@@ -94,13 +99,12 @@ export function parseJSONLD(jsonLD, set) {
9499
let triplets = [];
95100
let source = jsonLD['@id'];
96101

97-
// omeka s
98102
if (set) {
99103
triplets.push({
100104
source: set['@id'],
101105
target: source,
102106
img:
103-
jsonLD[config.paths.img[0]]?.[0]['@id'] ||
107+
jsonLD[config.paths.img[0]]?.[0]?.['@id'] ||
104108
getNestedValue(jsonLD, config.paths.img.join('.')),
105109
title: jsonLD[config.title]
106110
});
@@ -125,11 +129,11 @@ export function parseJSONLD(jsonLD, set) {
125129
.replace(/\/media\//, '/resources/')
126130
.replace(/\/item_sets\//, '/resources/');
127131

128-
const title = obj[config.paths.title] || obj.display_title || obj['@id']; // omeka s
132+
const title = obj[config.paths.title] || obj.display_title || obj['@id'];
129133
const img =
130134
obj?.thumbnail_url ||
131135
obj?.[config.paths.img?.[0]]?.[0]?.['@id'] ||
132-
getNestedValue(obj, config.paths.img.join('.')); // omeka s
136+
getNestedValue(obj, config.paths.img.join('.'));
133137

134138
let property =
135139
obj[config.property]?.replace('_', ' ')?.replace(regex, '') ||
@@ -139,8 +143,6 @@ export function parseJSONLD(jsonLD, set) {
139143
(triplet) => triplet.source === source && triplet.target === target
140144
);
141145

142-
// console.log(property)
143-
144146
if (!exists && !config.hideProperties.includes(property)) {
145147
triplets.push({
146148
source: source,
@@ -149,7 +151,7 @@ export function parseJSONLD(jsonLD, set) {
149151
img,
150152
property,
151153
reverse,
152-
external: target.includes(config.url) ? false : true
154+
external: typeof target === 'string' && target.includes(config.url) ? false : true
153155
});
154156
}
155157
} else if (typeof obj[key] === 'object') {
@@ -175,25 +177,25 @@ export function parseJSONLD(jsonLD, set) {
175177
export function getNestedValue(obj, path) {
176178
return path.split('.').reduce((o, key) => (o || {})[key], obj);
177179
}
180+
178181
export function getItemThumbnail(item, allEntities, preferredSize = 'large') {
179-
if (!item) return null;
180-
181-
// Direct: sometimes image is in the item
182-
if (item.thumbnail_display_urls && item.thumbnail_display_urls[preferredSize]) {
183-
return item.thumbnail_display_urls[preferredSize];
184-
}
185-
186-
// Or in o:media
187-
const mediaArr = item['o:media'];
188-
if (!mediaArr || !mediaArr.length) return null;
189-
190-
for (let mediaRef of mediaArr) {
191-
// Find media entity
192-
let mediaObj = allEntities.find(ent => ent['@id'] === mediaRef['@id'] || ent['o:id'] === mediaRef['o:id']);
193-
if (mediaObj?.thumbnail_display_urls && mediaObj.thumbnail_display_urls[preferredSize]) {
194-
return mediaObj.thumbnail_display_urls[preferredSize];
195-
}
196-
}
197-
198-
return null;
182+
if (!item) return null;
183+
184+
if (item.thumbnail_display_urls && item.thumbnail_display_urls[preferredSize]) {
185+
return item.thumbnail_display_urls[preferredSize];
186+
}
187+
188+
const mediaArr = item['o:media'];
189+
if (!mediaArr || !mediaArr.length) return null;
190+
191+
for (let mediaRef of mediaArr) {
192+
let mediaObj = allEntities.find(
193+
(ent) => ent['@id'] === mediaRef['@id'] || ent['o:id'] === mediaRef['o:id']
194+
);
195+
if (mediaObj?.thumbnail_display_urls && mediaObj.thumbnail_display_urls[preferredSize]) {
196+
return mediaObj.thumbnail_display_urls[preferredSize];
197+
}
198+
}
199+
200+
return null;
199201
}

static/db2.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

svelte.config.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,22 @@ const dev = process.argv.includes('dev');
77
/** @type {import('@sveltejs/kit').Config} */
88
const config = {
99
extensions: ['.svelte', ...mdsvexConfig.extensions],
10-
preprocess: [
11-
mdsvex(mdsvexConfig)
12-
],
10+
preprocess: [mdsvex(mdsvexConfig)],
1311
kit: {
1412
adapter: adapter({
1513
fallback: '404.html'
1614
}),
1715
paths: {
18-
base: dev ? '' : process.env.BASE_PATH,
16+
base: dev ? '' : process.env.BASE_PATH
1917
},
2018
alias: {
2119
'@components': 'src/components',
2220
'@stores': 'src/stores.js',
2321
'@db': 'src/lib/db.js',
2422
'@utils': 'src/utils.js',
25-
'@setup': 'src/setup.json',
23+
'@setup': 'src/setup.json'
2624
}
2725
}
2826
};
2927

30-
export default config;
28+
export default config;

0 commit comments

Comments
 (0)