From 27ff46ca7dbf6d228bbc5f1b5eb14f97fb74abaf Mon Sep 17 00:00:00 2001 From: vmishenev Date: Thu, 11 Jan 2024 01:06:38 +0200 Subject: [PATCH] Add comment --- .../allModulesPage/ExternalModuleLinkResolver.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dokka-subprojects/plugin-all-modules-page/src/main/kotlin/org/jetbrains/dokka/allModulesPage/ExternalModuleLinkResolver.kt b/dokka-subprojects/plugin-all-modules-page/src/main/kotlin/org/jetbrains/dokka/allModulesPage/ExternalModuleLinkResolver.kt index c937f94344d..0947d1fafc1 100644 --- a/dokka-subprojects/plugin-all-modules-page/src/main/kotlin/org/jetbrains/dokka/allModulesPage/ExternalModuleLinkResolver.kt +++ b/dokka-subprojects/plugin-all-modules-page/src/main/kotlin/org/jetbrains/dokka/allModulesPage/ExternalModuleLinkResolver.kt @@ -89,13 +89,19 @@ public class DefaultExternalModuleLinkResolver( } else true }?.first ?: return null - val modulePath = context.configuration.outputDir.absolutePath - val modulePathParts = modulePath.split(File.separator) + // relativization [fileContext] path over output path (or `fileContext.relativeTo(outputPath)`) + // e.g. outputPath = `/a/b/` + // fileContext = `/a/c/d/index.html` + // will be transformed to `../../b`+ validLink + val outputPath = context.configuration.outputDir.absolutePath + + + val outputPathParts = outputPath.split(File.separator) val contextPathParts = fileContext.absolutePath.split(File.separator) - val commonPathElements = modulePathParts.zip(contextPathParts) + val commonPathElements = outputPathParts.zip(contextPathParts) .takeWhile { (a, b) -> a == b }.count() - return (List(contextPathParts.size - commonPathElements - 1) { ".." } + modulePathParts.drop(commonPathElements)) + return (List(contextPathParts.size - commonPathElements - 1) { ".." } + outputPathParts.drop(commonPathElements)) .joinToString("/") + validLink.removePrefix("file:") }