Skip to content

Navigation displays only flatten package structure #10299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ window.addEventListener('DOMContentLoaded', () => {
})

revealNavigationForCurrentPage = () => {
let pageId = document.getElementById("content").attributes["pageIds"].value.toString();
let pageIdParts = document.getElementById("content").attributes["pageIds"].value.toString().split("/")
let parts = document.querySelectorAll(".sideMenuPart");
let found = 0;
do {
let pageId = pageIdParts.join("/")
parts.forEach(part => {
if (part.attributes['pageId'].value.indexOf(pageId) !== -1 && found === 0) {
found = 1;
Expand All @@ -42,8 +43,8 @@ revealNavigationForCurrentPage = () => {
revealParents(part)
}
});
pageId = pageId.substring(0, pageId.lastIndexOf("/"))
} while (pageId.indexOf("/") !== -1 && found === 0)
pageIdParts.pop()
} while (pageIdParts.length > 0)
};

revealParents = (part) => {
Expand Down
27 changes: 22 additions & 5 deletions scala3doc/src/dotty/dokka/site/processors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import java.nio.file.FileVisitOption

import org.jetbrains.dokka.base.renderers.html.{NavigationNode, NavigationPage}
import org.jetbrains.dokka.model.Documentable
import org.jetbrains.dokka.model.DPackage
import org.jetbrains.dokka.model.DModule
import org.jetbrains.dokka.pages._
import org.jetbrains.dokka.transformers.pages.PageTransformer

import scala.collection.JavaConverters._
import dotty.dokka.model.api._

abstract class BaseStaticSiteProcessor(staticSiteContext: Option[StaticSiteContext]) extends PageTransformer:
final override def invoke(input: RootPageNode): RootPageNode = staticSiteContext.fold(input)(transform(input, _))
Expand Down Expand Up @@ -118,22 +121,36 @@ class RootIndexPageCreator(ctx: Option[StaticSiteContext]) extends BaseStaticSit
val (contentNodes, nonContent) = input.getChildren.asScala.partition { _.isInstanceOf[ContentNode] }
val (navigations, rest) = nonContent.partition { _.isInstanceOf[NavigationPage] }
val modifiedNavigation = navigations.map { it =>
val root = it.asInstanceOf[NavigationPage].getRoot
val api = root.getChildren.asScala.filter(_.getDri == apiPageDRI)
val sourceSets = it.asInstanceOf[NavigationPage].getRoot.getSourceSets
def flatMapPackages(pn: PageNode): List[NavigationNode] =
def processChildren = pn.getChildren.asScala.flatMap(flatMapPackages).toList
pn match
case cp: ContentPage => cp.getDocumentable match
case null =>
processChildren
case p: DPackage =>
List(new NavigationNode(p.getName, p.getDri, sourceSets, JList())) ++ processChildren
case other =>
Nil
case _ =>
Nil

val packagesNavigation = input.getChildren.asScala.flatMap(flatMapPackages).sortBy(_.getName)
val api = new NavigationNode("API", apiPageDRI, sourceSets, packagesNavigation.asJava)

def toNavigationNode(page: StaticPageNode): NavigationNode = NavigationNode(
page.title(),
page.getDri.asScala.head,
root.getSourceSets,
sourceSets,
page.getChildren.asScala.collect { case p: StaticPageNode => toNavigationNode(p)}.asJava
)

new NavigationPage(
new NavigationNode(
input.getName,
docsRootDRI,
root.getSourceSets,
(ctx.mainPages.map(toNavigationNode) ++ api).asJava
sourceSets,
(ctx.mainPages.map(toNavigationNode) ++ Seq(api)).asJava
)
)
}
Expand Down