aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/resolvers
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/resolvers')
-rw-r--r--core/src/main/kotlin/resolvers/DefaultLocationProvider.kt14
-rw-r--r--core/src/main/kotlin/resolvers/LocationProvider.kt1
2 files changed, 11 insertions, 4 deletions
diff --git a/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt b/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt
index c5243233..f8faa45b 100644
--- a/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt
+++ b/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt
@@ -17,6 +17,9 @@ open class DefaultLocationProvider(private val pageGraphRoot: PageNode, val conf
.flatMap { it.externalDocumentationLinks }.map { it.packageListUrl }.distinct()
)
+ override fun resolveRoot(node: PageNode): String = "../${pathTo(pageGraphRoot, node).removeSuffix(
+ PAGE_WITH_CHILDREN_SUFFIX)}"
+
protected open fun findInPageGraph(dri: DRI, platforms: List<PlatformData>): PageNode? = pageGraphRoot.dfs { it.dri == dri }
protected open fun pathTo(node: PageNode, context: PageNode?): String {
@@ -25,12 +28,15 @@ open class DefaultLocationProvider(private val pageGraphRoot: PageNode, val conf
if (this is PackagePageNode) name
else identifierToFilename(name)
- fun getPath(pathNode: PageNode?, path: List<String> = mutableListOf()): List<String> =
- if (pathNode == null) path
- else getPath(pathNode.parent, path + pathNode.pathName() )
+ fun getPath(pathNode: PageNode?, path: List<String> = mutableListOf()): List<String> = when(pathNode) {
+ null -> path
+ pageGraphRoot -> path + "root"
+ else -> getPath(pathNode.parent, path + pathNode.pathName())
+ }
+ val contextNode = if (context?.children?.isEmpty() == true) context.parent else context
val nodePath = getPath(node).reversed()
- val contextPath = getPath(context).reversed()
+ val contextPath = getPath(contextNode).reversed()
val commonPathElements = nodePath.zip(contextPath).takeWhile { (a, b) -> a == b }.size
diff --git a/core/src/main/kotlin/resolvers/LocationProvider.kt b/core/src/main/kotlin/resolvers/LocationProvider.kt
index e55c712d..9f02d347 100644
--- a/core/src/main/kotlin/resolvers/LocationProvider.kt
+++ b/core/src/main/kotlin/resolvers/LocationProvider.kt
@@ -7,4 +7,5 @@ import org.jetbrains.dokka.pages.PlatformData
interface LocationProvider {
fun resolve(dri: DRI, platforms: List<PlatformData>, context: PageNode? = null): String
fun resolve(node: PageNode, context: PageNode? = null): String
+ fun resolveRoot(node: PageNode): String
}