mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
fix #2862
This commit is contained in:
parent
d082f705bc
commit
567eecc0db
@ -141,34 +141,26 @@ class EpubFile(var book: Book) {
|
|||||||
val startFragmentId = chapter.startFragmentId
|
val startFragmentId = chapter.startFragmentId
|
||||||
val endFragmentId = chapter.endFragmentId
|
val endFragmentId = chapter.endFragmentId
|
||||||
val elements = Elements()
|
val elements = Elements()
|
||||||
var hasMoreResources = false
|
var findChapterFirstSource = false
|
||||||
val includeNextChapterResource = !endFragmentId.isNullOrBlank()
|
val includeNextChapterResource = !endFragmentId.isNullOrBlank()
|
||||||
/*一些书籍依靠href索引的resource会包含多个章节,需要依靠fragmentId来截取到当前章节的内容*/
|
/*一些书籍依靠href索引的resource会包含多个章节,需要依靠fragmentId来截取到当前章节的内容*/
|
||||||
/*注:这里较大增加了内容加载的时间,所以首次获取内容后可存储到本地cache,减少重复加载*/
|
/*注:这里较大增加了内容加载的时间,所以首次获取内容后可存储到本地cache,减少重复加载*/
|
||||||
for (res in epubBook.contents) {
|
for (res in epubBook.contents) {
|
||||||
val isFirstResource = chapter.url.substringBeforeLast("#") == res.href
|
if (!findChapterFirstSource) {
|
||||||
val isNextChapterResource = res.href == nextUrl?.substringBeforeLast("#")
|
if (chapter.url == res.href) findChapterFirstSource = true
|
||||||
if (isFirstResource) {
|
|
||||||
// add first resource to elements
|
// add first resource to elements
|
||||||
elements.add(
|
elements.add(
|
||||||
/* pass endFragmentId if only has one resource */
|
/* pass endFragmentId if only has one resource */
|
||||||
getBody(res, startFragmentId, endFragmentId)
|
getBody(res, startFragmentId, endFragmentId)
|
||||||
)
|
)
|
||||||
// check current resource
|
if (chapter.url == nextUrl) break
|
||||||
if (isNextChapterResource) {
|
continue
|
||||||
/* FragmentId should not be same in same resource */
|
|
||||||
if (!endFragmentId.isNullOrBlank() && endFragmentId == startFragmentId)
|
|
||||||
AppLog.putDebug("Epub: Resource (${res.href}) has same FragmentId, check the file: ${book.bookUrl}")
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
hasMoreResources = true
|
if (nextUrl != res.href) {
|
||||||
} else if (hasMoreResources) {
|
|
||||||
if (isNextChapterResource) {
|
|
||||||
if (includeNextChapterResource) elements.add(getBody(res, null/* FragmentId may be same in different resources, pass null */, endFragmentId))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
// rest resource should not have fragmentId, pass null
|
|
||||||
elements.add(getBody(res, null, null))
|
elements.add(getBody(res, null, null))
|
||||||
|
} else {
|
||||||
|
elements.add(getBody(res, null, endFragmentId))
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//title标签中的内容不需要显示在正文中,去除
|
//title标签中的内容不需要显示在正文中,去除
|
||||||
@ -364,7 +356,7 @@ class EpubFile(var book: Book) {
|
|||||||
val chapter = BookChapter()
|
val chapter = BookChapter()
|
||||||
chapter.bookUrl = book.bookUrl
|
chapter.bookUrl = book.bookUrl
|
||||||
chapter.title = ref.title
|
chapter.title = ref.title
|
||||||
chapter.url = ref.completeHref
|
chapter.url = ref.completeHref.substringBeforeLast("#")
|
||||||
chapter.startFragmentId = ref.fragmentId
|
chapter.startFragmentId = ref.fragmentId
|
||||||
chapterList.lastOrNull()?.endFragmentId = chapter.startFragmentId
|
chapterList.lastOrNull()?.endFragmentId = chapter.startFragmentId
|
||||||
chapterList.lastOrNull()?.putVariable("nextUrl", chapter.url)
|
chapterList.lastOrNull()?.putVariable("nextUrl", chapter.url)
|
||||||
|
Loading…
Reference in New Issue
Block a user