Skip to content

Commit c421493

Browse files
committed
Add normalizeDescription function, fix OL description
1 parent 3d1d0c4 commit c421493

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/extractors/openlibrary.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Extractor } from "./AbstractExtractor.js"
2-
import { addContributor, collectObject, getCoverData, normalizeReadingFormat, remapKeys } from "../shared/utils.js";
2+
import { addContributor, collectObject, getCoverData, normalizeDescription, normalizeReadingFormat, remapKeys } from "../shared/utils.js";
33

44
// references:
55
// https://openlibrary.org/dev/docs/api/books
@@ -83,7 +83,10 @@ async function getDetails(idUrl) {
8383
details["Title"] = data["title"];
8484
}
8585
if ("description" in data) {
86-
details["Description"] = data["description"];
86+
const description = normalizeDescription(data["description"]);
87+
if (description) {
88+
details["Description"] = description;
89+
}
8790
}
8891
if ("identifiers" in data) {
8992
Object.entries(data["identifiers"]).forEach(([k, v]) => {

src/shared/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,16 @@ export function remapKeys(mapping, object) {
227227
return newObj;
228228
}
229229

230+
export function normalizeDescription(description) {
231+
if (typeof description === "string") return description;
232+
if (Array.isArray(description)) return normalizeDescription(description[0]);
233+
if (description && typeof description === "object") {
234+
if (typeof description.value === "string") return description.value;
235+
if (typeof description.text === "string") return description.text;
236+
}
237+
return "";
238+
}
239+
230240
/**
231241
* @typedef {{name: string, roles: string[]}} contributor
232242
*/

0 commit comments

Comments
 (0)