diff --git a/server/finders/BookFinder.js b/server/finders/BookFinder.js index ac3de2a7..7d26b6bf 100644 --- a/server/finders/BookFinder.js +++ b/server/finders/BookFinder.js @@ -439,6 +439,8 @@ function replaceAccentedChars(str) { function cleanTitleForCompares(title) { if (!title) return '' + title = stripRedundantSpaces(title) + // Remove subtitle if there (i.e. "Cool Book: Coolest Ever" becomes "Cool Book") let stripped = stripSubtitle(title) @@ -452,6 +454,8 @@ function cleanTitleForCompares(title) { function cleanAuthorForCompares(author) { if (!author) return '' + author = stripRedundantSpaces(author) + let cleanAuthor = replaceAccentedChars(author).toLowerCase() // separate initials cleanAuthor = cleanAuthor.replace(/([a-z])\.([a-z])/g, '$1. $2') @@ -459,3 +463,7 @@ function cleanAuthorForCompares(author) { cleanAuthor = cleanAuthor.replace(/(?<=\w\w)(\s+[a-z]\.?)+(?=\s+\w\w)/g, '') return cleanAuthor } + +function stripRedundantSpaces(str) { + return str.replace(/\s+/g, ' ').trim() +}