mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-02 21:44:56 +02:00
Makes it so the when sorting and ignoring prefixes, they are actually ignored
This commit is contained in:
parent
c6e9fe6513
commit
473257f65e
6 changed files with 45 additions and 32 deletions
|
@ -140,14 +140,24 @@ module.exports.cleanStringForSearch = (str) => {
|
|||
return str.toLowerCase().replace(/[\'\.\`\",]/g, '').trim()
|
||||
}
|
||||
|
||||
module.exports.getTitleIgnorePrefix = (title) => {
|
||||
if (!title) return ''
|
||||
const getTitleParts = (title) => {
|
||||
if (!title) return ['', null]
|
||||
var prefixesToIgnore = global.ServerSettings.sortingPrefixes || []
|
||||
prefixes = []
|
||||
for (const prefix of prefixesToIgnore) {
|
||||
// e.g. for prefix "the". If title is "The Book" return "Book, The"
|
||||
if (title.toLowerCase().startsWith(`${prefix} `)) {
|
||||
return title.substr(prefix.length + 1) + `, ${prefix.substr(0, 1).toUpperCase() + prefix.substr(1)}`
|
||||
return [title.substr(prefix.length + 1), `${prefix.substr(0, 1).toUpperCase() + prefix.substr(1)}`]
|
||||
}
|
||||
}
|
||||
return title
|
||||
return [title, null]
|
||||
}
|
||||
|
||||
module.exports.getTitleIgnorePrefix = (title) => {
|
||||
return getTitleParts(title)[0]
|
||||
}
|
||||
|
||||
module.exports.getTitlePrefixAtEnd = (title) => {
|
||||
let [sort, prefix] = getTitleParts(title)
|
||||
return prefix ? `${sort}, ${prefix}` : title
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue