From db337c6b489d41f7c62bc44f9edb3e5eaa62e0d5 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Wed, 21 Apr 2021 13:10:03 +0200 Subject: Make anchors stable (#1851) * Make anchors stable * Remove backing field from merged and all in CompositeSourceSetID --- plugins/base/src/main/kotlin/renderers/pageId.kt | 11 ++++++++++- .../main/kotlin/resolvers/local/DokkaBaseLocationProvider.kt | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'plugins/base') diff --git a/plugins/base/src/main/kotlin/renderers/pageId.kt b/plugins/base/src/main/kotlin/renderers/pageId.kt index b80121c0..d3a9ed7a 100644 --- a/plugins/base/src/main/kotlin/renderers/pageId.kt +++ b/plugins/base/src/main/kotlin/renderers/pageId.kt @@ -11,8 +11,17 @@ internal val ContentPage.pageId: String internal val NavigationNode.pageId: String get() = pageId(dri, sourceSets) +@JvmName("shortenSourceSetsToUrl") +internal fun Set.shortenToUrl() = + sortedBy { it.sourceSetIDs.merged.let { it.scopeId + it.sourceSetName } }.joinToString().hashCode() + +internal fun DRI.shortenToUrl() = toString() + +@JvmName("shortenDrisToUrl") +internal fun Set.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): String = "$dri/${sourceSets.hashCode()}" \ No newline at end of file +private fun pageId(dri: DRI, sourceSets: Set): String = "${dri.shortenToUrl()}/${sourceSets.shortenToUrl()}" \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/resolvers/local/DokkaBaseLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DokkaBaseLocationProvider.kt index fa133045..41a9a7e2 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DokkaBaseLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DokkaBaseLocationProvider.kt @@ -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 @@ -17,6 +18,6 @@ abstract class DokkaBaseLocationProvider( * 2040 characters limit */ open fun anchorForDCI(dci: DCI, sourceSets: Set): String = - (dci.dri.toString() + "/" + dci.kind + "/" + sourceSets.hashCode()).urlEncoded() + (dci.dri.shortenToUrl().toString() + "/" + dci.kind + "/" + sourceSets.shortenToUrl()).urlEncoded() } -- cgit