Skip to content

Commit 7c7a8c8

Browse files
authored
Merge pull request #10299 from romanowski/scala3doc/better-api-navigation
Navigation displays only flatten package structure
2 parents dfe6f3e + a9b7cd6 commit 7c7a8c8

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

scala3doc/resources/dotty_res/scripts/fast-navigation-loader.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ window.addEventListener('DOMContentLoaded', () => {
2828
})
2929

3030
revealNavigationForCurrentPage = () => {
31-
let pageId = document.getElementById("content").attributes["pageIds"].value.toString();
31+
let pageIdParts = document.getElementById("content").attributes["pageIds"].value.toString().split("/")
3232
let parts = document.querySelectorAll(".sideMenuPart");
3333
let found = 0;
3434
do {
35+
let pageId = pageIdParts.join("/")
3536
parts.forEach(part => {
3637
if (part.attributes['pageId'].value.indexOf(pageId) !== -1 && found === 0) {
3738
found = 1;
@@ -42,8 +43,8 @@ revealNavigationForCurrentPage = () => {
4243
revealParents(part)
4344
}
4445
});
45-
pageId = pageId.substring(0, pageId.lastIndexOf("/"))
46-
} while (pageId.indexOf("/") !== -1 && found === 0)
46+
pageIdParts.pop()
47+
} while (pageIdParts.length > 0)
4748
};
4849

4950
revealParents = (part) => {

scala3doc/src/dotty/dokka/site/processors.scala

+22-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import java.nio.file.FileVisitOption
77

88
import org.jetbrains.dokka.base.renderers.html.{NavigationNode, NavigationPage}
99
import org.jetbrains.dokka.model.Documentable
10+
import org.jetbrains.dokka.model.DPackage
11+
import org.jetbrains.dokka.model.DModule
1012
import org.jetbrains.dokka.pages._
1113
import org.jetbrains.dokka.transformers.pages.PageTransformer
1214

1315
import scala.collection.JavaConverters._
16+
import dotty.dokka.model.api._
1417

1518
abstract class BaseStaticSiteProcessor(staticSiteContext: Option[StaticSiteContext]) extends PageTransformer:
1619
final override def invoke(input: RootPageNode): RootPageNode = staticSiteContext.fold(input)(transform(input, _))
@@ -118,22 +121,36 @@ class RootIndexPageCreator(ctx: Option[StaticSiteContext]) extends BaseStaticSit
118121
val (contentNodes, nonContent) = input.getChildren.asScala.partition { _.isInstanceOf[ContentNode] }
119122
val (navigations, rest) = nonContent.partition { _.isInstanceOf[NavigationPage] }
120123
val modifiedNavigation = navigations.map { it =>
121-
val root = it.asInstanceOf[NavigationPage].getRoot
122-
val api = root.getChildren.asScala.filter(_.getDri == apiPageDRI)
124+
val sourceSets = it.asInstanceOf[NavigationPage].getRoot.getSourceSets
125+
def flatMapPackages(pn: PageNode): List[NavigationNode] =
126+
def processChildren = pn.getChildren.asScala.flatMap(flatMapPackages).toList
127+
pn match
128+
case cp: ContentPage => cp.getDocumentable match
129+
case null =>
130+
processChildren
131+
case p: DPackage =>
132+
List(new NavigationNode(p.getName, p.getDri, sourceSets, JList())) ++ processChildren
133+
case other =>
134+
Nil
135+
case _ =>
136+
Nil
137+
138+
val packagesNavigation = input.getChildren.asScala.flatMap(flatMapPackages).sortBy(_.getName)
139+
val api = new NavigationNode("API", apiPageDRI, sourceSets, packagesNavigation.asJava)
123140

124141
def toNavigationNode(page: StaticPageNode): NavigationNode = NavigationNode(
125142
page.title(),
126143
page.getDri.asScala.head,
127-
root.getSourceSets,
144+
sourceSets,
128145
page.getChildren.asScala.collect { case p: StaticPageNode => toNavigationNode(p)}.asJava
129146
)
130147

131148
new NavigationPage(
132149
new NavigationNode(
133150
input.getName,
134151
docsRootDRI,
135-
root.getSourceSets,
136-
(ctx.mainPages.map(toNavigationNode) ++ api).asJava
152+
sourceSets,
153+
(ctx.mainPages.map(toNavigationNode) ++ Seq(api)).asJava
137154
)
138155
)
139156
}

0 commit comments

Comments
 (0)