refactor: normalize chapter titles for finding chapter hrefs

This commit is contained in:
Faizan Zafar 2024-08-25 16:28:34 -07:00
parent 79df705da7
commit ae50fb8df8

View file

@ -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