From 81e93c295725f3a6ad3a112cf3dff1a6b931b621 Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Tue, 5 Nov 2019 15:23:39 +0100 Subject: Fixing typo in location provider --- .../kotlin/resolvers/DefaultLocationProvider.kt | 24 +++++++++------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'core/src') diff --git a/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt b/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt index 65b27779..c5243233 100644 --- a/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt +++ b/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt @@ -21,29 +21,25 @@ open class DefaultLocationProvider(private val pageGraphRoot: PageNode, val conf protected open fun pathTo(node: PageNode, context: PageNode?): String { - fun getPath(pathNode: PageNode?, path: MutableList = mutableListOf()): List = - if (pathNode == null || pathNode == pageGraphRoot) - path - else - getPath(pathNode.parent, path.apply { - add(if (node is PackagePageNode) { - node.name - } else { - identifierToFilename(node.name) - }) - }) + fun PageNode.pathName(): String = + if (this is PackagePageNode) name + else identifierToFilename(name) + + fun getPath(pathNode: PageNode?, path: List = mutableListOf()): List = + if (pathNode == null) path + else getPath(pathNode.parent, path + pathNode.pathName() ) val nodePath = getPath(node).reversed() val contextPath = getPath(context).reversed() val commonPathElements = nodePath.zip(contextPath).takeWhile { (a, b) -> a == b }.size - return ( List(contextPath.size - commonPathElements) { ".." } + nodePath.drop(commonPathElements) ).joinToString("/") + - if(node.children.isNotEmpty()) PAGE_WITH_CHILDREN_SUFFIX else "" + return ( List(contextPath.size - commonPathElements) { ".." } + nodePath.drop(commonPathElements) + + if(node.children.isNotEmpty()) listOf(PAGE_WITH_CHILDREN_SUFFIX) else emptyList()).joinToString("/") } private companion object { - const val PAGE_WITH_CHILDREN_SUFFIX = "/index" + const val PAGE_WITH_CHILDREN_SUFFIX = "index" } } -- cgit