From dd55621b7bd8aa306465b4c5fec65d2a8eff8a7b Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Tue, 26 Nov 2024 13:24:59 +0000 Subject: [PATCH] Do not miss non-leaf titles. (Ticket: #PP-1954) --- README-CHANGES.xml | 10 ++++++++-- .../r2/vanilla/internal/SR2NavigationGraphs.kt | 9 ++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README-CHANGES.xml b/README-CHANGES.xml index e49d687..74adaf8 100644 --- a/README-CHANGES.xml +++ b/README-CHANGES.xml @@ -171,8 +171,14 @@ - - + + + + + + + + diff --git a/org.librarysimplified.r2.vanilla/src/main/java/org/librarysimplified/r2/vanilla/internal/SR2NavigationGraphs.kt b/org.librarysimplified.r2.vanilla/src/main/java/org/librarysimplified/r2/vanilla/internal/SR2NavigationGraphs.kt index c972f7d..d18fb80 100644 --- a/org.librarysimplified.r2.vanilla/src/main/java/org/librarysimplified/r2/vanilla/internal/SR2NavigationGraphs.kt +++ b/org.librarysimplified.r2.vanilla/src/main/java/org/librarysimplified/r2/vanilla/internal/SR2NavigationGraphs.kt @@ -49,7 +49,7 @@ object SR2NavigationGraphs { private fun makeNavigationPoint(publication: Publication, link: Link): SR2NavigationPoint { val title = link.title?.takeIf(String::isNotBlank) - ?: titleFromTOC(publication.tableOfContents, link) + ?: titleFromTOC(null, publication.tableOfContents, link) ?: "" return SR2NavigationPoint( title, @@ -62,9 +62,9 @@ object SR2NavigationGraphs { * In case of multiples matches, deeper items have precedence because they're likely to be more specific. */ - private fun titleFromTOC(toc: List, link: Link): String? { + private fun titleFromTOC(tocEntryParent: Link?, toc: List, link: Link): String? { for (entry in toc) { - this.titleFromTOC(entry.children, link)?.let { + this.titleFromTOC(entry, entry.children, link)?.let { return it } } @@ -75,6 +75,9 @@ object SR2NavigationGraphs { } } + if (tocEntryParent?.href == link.href && tocEntryParent.title != null) { + return tocEntryParent.title + } return null } }