Skip to content

Commit

Permalink
refactor: normalize chapter titles for finding chapter hrefs
Browse files Browse the repository at this point in the history
  • Loading branch information
BimBimSalaBim committed Aug 25, 2024
1 parent 79df705 commit ae50fb8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion client/components/readers/EpubReader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,12 @@ export default {
return chapter.title || audioBookChapters[audioBookChapters.length - 1].title
},
findChapterHref(title) {
const normalizeString = (str) => {
return str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase()
}
const findInToc = (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) {
const result = findInToc(item.subitems)
if (result) return result
Expand Down

0 comments on commit ae50fb8

Please sign in to comment.