mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-09 19:01:41 +00:00
refactor: normalize chapter titles for finding chapter hrefs
This commit is contained in:
parent
79df705da7
commit
ae50fb8df8
1 changed files with 4 additions and 1 deletions
|
|
@ -470,9 +470,12 @@ export default {
|
||||||
return chapter.title || audioBookChapters[audioBookChapters.length - 1].title
|
return chapter.title || audioBookChapters[audioBookChapters.length - 1].title
|
||||||
},
|
},
|
||||||
findChapterHref(title) {
|
findChapterHref(title) {
|
||||||
|
const normalizeString = (str) => {
|
||||||
|
return str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase()
|
||||||
|
}
|
||||||
const findInToc = (items) => {
|
const findInToc = (items) => {
|
||||||
for (let item of items) {
|
for (let item of items) {
|
||||||
if (item.label.trim() === title) return item.href
|
if (normalizeString(item.label) === normalizeString(title)) return item.href
|
||||||
if (item.subitems) {
|
if (item.subitems) {
|
||||||
const result = findInToc(item.subitems)
|
const result = findInToc(item.subitems)
|
||||||
if (result) return result
|
if (result) return result
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue