@@ -112,15 +112,10 @@ class StaticSiteLocationProvider(pageNode: RootPageNode)(using ctx: DokkaContext
112112 override def pathTo (node : PageNode , context : PageNode ): String =
113113 if node == context then " "
114114 else
115- val nodePaths = getPathsIndex.get(node).asScala
116- val contextPaths = Option (context).fold(Nil )(getPathsIndex.get(_).asScala.dropRight( 1 ))
117- val commonPaths = nodePaths.zip (contextPaths).takeWhile{ case (a, b) => a == b }.size
115+ val nodePaths = getPathsIndex.get(node).asScala.toList
116+ val contextPaths = Option (context).fold(Nil )(getPathsIndex.get(_).asScala).toList
117+ relativePath (contextPaths, nodePaths)
118118
119- val contextPath = contextPaths.drop(commonPaths).map(_ => " .." )
120- val nodePath = nodePaths.drop(commonPaths) match
121- case l if l.isEmpty => Seq (" index" )
122- case l => l
123- (contextPath ++ nodePath).mkString(" /" )
124119
125120 val externalLocationProviders : List [(List [Regex ], ExternalLocationProvider )] =
126121 val sourceSet = ctx.getConfiguration.getSourceSets.asScala(0 )
@@ -155,4 +150,15 @@ class StaticSiteLocationProvider(pageNode: RootPageNode)(using ctx: DokkaContext
155150 regexes.exists(r => r.matches(path))
156151 }.fold(null )(_(1 ).resolve(dri.withNoOrigin))
157152 case None => null
158- }
153+ }
154+
155+ def relativePath (fullFrom : Seq [String ], to : Seq [String ]): String =
156+ val from = fullFrom.dropRight(1 )
157+ val commonPaths = to.zip(from).takeWhile{ case (a, b) => a == b }.size
158+
159+ val contextPath = from.drop(commonPaths).map(_ => " .." )
160+ val nodePath = to.drop(commonPaths) match
161+ case Nil if contextPath.isEmpty && to.nonEmpty=> Seq (" .." , to.last)
162+ case Nil => Seq (" index" )
163+ case l => l
164+ (contextPath ++ nodePath).mkString(" /" )
0 commit comments