Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add comment
Browse files Browse the repository at this point in the history
vmishenev committed Jan 10, 2024
1 parent 0a830ae commit 27ff46c
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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:")
}

0 comments on commit 27ff46c

Please sign in to comment.