Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make anchors stable #1851

Merged
merged 2 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions core/src/main/kotlin/model/CompositeSourceSetID.kt
Expand Up @@ -13,12 +13,16 @@ data class CompositeSourceSetID(
require(children.isNotEmpty()) { "Expected at least one source set id" }
}

val merged = DokkaSourceSetID(
scopeId = children.joinToString(separator = "+") { it.scopeId },
sourceSetName = children.joinToString(separator = "+") { it.sourceSetName }
)

val all: Set<DokkaSourceSetID> = setOf(merged, *children.toTypedArray())
val merged: DokkaSourceSetID
get() = children.sortedBy { it.scopeId + it.sourceSetName }.let { sortedChildren ->
DokkaSourceSetID(
scopeId = sortedChildren.joinToString(separator = "+") { it.scopeId },
sourceSetName = sortedChildren.joinToString(separator = "+") { it.sourceSetName }
)
}

val all: Set<DokkaSourceSetID>
get() = setOf(merged, *children.toTypedArray())

operator fun contains(sourceSetId: DokkaSourceSetID): Boolean {
return sourceSetId in all
Expand Down
11 changes: 10 additions & 1 deletion plugins/base/src/main/kotlin/renderers/pageId.kt
Expand Up @@ -11,8 +11,17 @@ internal val ContentPage.pageId: String
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/${sourceSets.hashCode()}"
private fun pageId(dri: DRI, sourceSets: Set<DisplaySourceSet>): String = "${dri.shortenToUrl()}/${sourceSets.shortenToUrl()}"
@@ -1,5 +1,6 @@
package org.jetbrains.dokka.base.resolvers.local

import org.jetbrains.dokka.base.renderers.shortenToUrl
import org.jetbrains.dokka.model.DisplaySourceSet
import org.jetbrains.dokka.pages.DCI
import org.jetbrains.dokka.pages.RootPageNode
Expand All @@ -17,6 +18,6 @@ abstract class DokkaBaseLocationProvider(
* 2040 characters limit
*/
open fun anchorForDCI(dci: DCI, sourceSets: Set<DisplaySourceSet>): String =
(dci.dri.toString() + "/" + dci.kind + "/" + sourceSets.hashCode()).urlEncoded()
(dci.dri.shortenToUrl().toString() + "/" + dci.kind + "/" + sourceSets.shortenToUrl()).urlEncoded()

}