Skip to content

Commit 643530f

Browse files
authored
Merge pull request #27 from blue-core-lod/handle-mainTitle
Fixes extracting mainTitle if language code is present
2 parents f111cf0 + fe69d9f commit 643530f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/sinopiaSearch.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,28 @@ const hitsToResult = (payload) => {
138138
} else {
139139
rdfTypes.push(`http://id.loc.gov/ontologies/bibframe/${types}`)
140140
}
141+
// Extract label from JSON-LD format if needed
142+
const mainTitle = hit.data.title.mainTitle
143+
let label = mainTitle
144+
145+
// Handle array of titles
146+
if (Array.isArray(mainTitle)) {
147+
// Map each title to extract @value if it's an object, otherwise use as-is
148+
const titles = mainTitle.map(title => {
149+
if (title && typeof title === 'object' && '@value' in title) {
150+
return title['@value']
151+
}
152+
return title
153+
})
154+
// Join multiple titles with a separator
155+
label = titles.join(' / ')
156+
} else if (mainTitle && typeof mainTitle === 'object' && '@value' in mainTitle) {
157+
// Handle single JSON-LD object
158+
label = mainTitle['@value']
159+
}
141160
results.push({
142161
uri: hit.uri,
143-
label: hit.data.title.mainTitle,
162+
label: label,
144163
created: hit.created_at,
145164
modified: hit.updated_at,
146165
type: rdfTypes,

0 commit comments

Comments
 (0)