aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/renderers/pageId.kt
blob: f5d75cfc0ab1a2ec071a54dac8764506720f9386 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package org.jetbrains.dokka.base.renderers

import org.jetbrains.dokka.base.renderers.html.NavigationNode
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.DisplaySourceSet
import org.jetbrains.dokka.pages.ContentPage

internal val ContentPage.pageId: String
    get() = pageId(dri.first(), sourceSets())

internal val NavigationNode.pageId: String
    get() = pageId(dri, sourceSets)

@JvmName("shortenSourceSetsToUrl")
internal fun Set<DisplaySourceSet>.shortenToUrl() =
    sortedBy { it.sourceSetIDs.merged.let { it.scopeId + it.sourceSetName } }.joinToString().hashCode()

internal fun DRI.shortenToUrl() = toString()

@JvmName("shortenDrisToUrl")
internal fun Set<DRI>.shortenToUrl() = sortedBy { it.toString() }.joinToString().hashCode()

/**
 * Page Id is required to have a sourceSet in order to distinguish between different pages that has same DRI but different sourceSet
 * like main functions that are not expect/actual
 */
private fun pageId(dri: DRI, sourceSets: Set<DisplaySourceSet>): String = "${dri.shortenToUrl()}/${sourceSets.shortenToUrl()}"