aboutsummaryrefslogtreecommitdiff
path: root/src/Locations/FoldersLocationService.kt
blob: db06dc2c5ecd549785973dd51b961a9240ad69a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package org.jetbrains.dokka

import java.io.File

public fun FoldersLocationService(root: String): FoldersLocationService = FoldersLocationService(File(root))
public class FoldersLocationService(val root: File) : LocationService {
    override fun location(node: DocumentationNode): Location {
        val parts = node.path.map { identifierToFilename(it.name) }
        val folder = if (node.members.none()) {
            // leaf node, use file in owner's folder
            parts.joinToString("/", limit = parts.size - 1, truncated = "") + "/" + parts.last()
        } else {
            parts.joinToString("/") + (if (parts.none()) "" else "/") + "index"
        }
        return Location(File(root, folder))
    }
}