@@ -20,29 +20,40 @@ class StaticSiteLocationProvider(ctx: DokkaContext, pageNode: RootPageNode)
20
20
private def updatePageEntry (page : PageNode , jpath : JList [String ]): JList [String ] =
21
21
page match
22
22
case page : StaticPageNode =>
23
- if (page.getDri.contains(docsRootDRI)) JList (" index" )
24
- else {
25
- val path = jpath.asScala.toList
26
- val start = if (path.head == " --root--" ) List (" docs" ) else path.take(1 )
27
- // Dokka has a bug in location provider that does not properly handles relative paths for leaf nodes
28
- // This forces us to not change default paths on non-leaf nodes
29
- val newName = if page.getChildren.size() > 0 then path.last else
30
- val pageName = page.template.file.getName
31
- val dotIndex = pageName.lastIndexOf('.' )
32
- if (dotIndex < 0 ) pageName else pageName.substring(0 , dotIndex)
33
-
34
- println(s " Using $newName for ${page.template.file} orignally: $path" )
35
-
36
- (start ++ path.drop(1 ).dropRight(1 ) ++ List (newName)).asJava
23
+ ctx.siteContext.fold(jpath) { context =>
24
+ val rawFilePath = context.root.toPath.relativize(page.template.file.toPath)
25
+ val pageName = page.template.file.getName
26
+ val dotIndex = pageName.lastIndexOf('.' )
27
+ val newPath =
28
+ if (dotIndex < 0 ) rawFilePath.resolve(" index" )
29
+ else rawFilePath.resolveSibling(pageName.substring(0 , dotIndex))
30
+
31
+ newPath.iterator.asScala.map(_.toString).toList.asJava
37
32
}
33
+
38
34
case page : ContentPage if page.getDri.contains(docsDRI) =>
39
- JList (" docs" )
35
+ JList (" docs" , " index " )
40
36
case page : ContentPage if page.getDri.contains(apiPageDRI) =>
41
37
JList (" api" , " index" )
42
38
case _ if jpath.size() > 1 && jpath.get(0 ) == " --root--" && jpath.get(1 ) == " -a-p-i" =>
43
39
(List (" api" ) ++ jpath.asScala.drop(2 )).asJava
40
+
41
+ case _ : org.jetbrains.dokka.pages.ModulePage if ctx.siteContext.isEmpty =>
42
+ JList (" index" )
44
43
case _ =>
45
44
jpath
46
45
47
46
override val getPathsIndex : JMap [PageNode , JList [String ]] =
48
47
super .getPathsIndex.asScala.mapValuesInPlace(updatePageEntry).asJava
48
+
49
+
50
+ override def pathTo (node : PageNode , context : PageNode ): String =
51
+ val nodePaths = getPathsIndex.get(node).asScala
52
+ val contextPaths = Option (context).fold(Nil )(getPathsIndex.get(_).asScala.dropRight(1 ))
53
+ val commonPaths = nodePaths.zip(contextPaths).takeWhile{ case (a, b) => a == b }.size
54
+
55
+ val contextPath = contextPaths.drop(commonPaths).map(_ => " .." )
56
+ val nodePath = nodePaths.drop(commonPaths) match
57
+ case l if l.isEmpty => Seq (" index" )
58
+ case l => l
59
+ (contextPath ++ nodePath).mkString(" /" )
0 commit comments