Skip to content

Commit

Permalink
fix: stop including playground.js in Dokka pages and correctly filter…
Browse files Browse the repository at this point in the history
… for internal APIs (#1404)
  • Loading branch information
ianbotsf authored Sep 13, 2024
1 parent 55b6073 commit 77014ed
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

package aws.sdk.kotlin.dokka

import aws.sdk.kotlin.dokka.transformers.DisablePlaygroundIntegration
import aws.sdk.kotlin.dokka.transformers.FilterInternalApis
import aws.sdk.kotlin.dokka.transformers.NoOpSearchbarDataInstaller
import org.jetbrains.dokka.CoreExtensions
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.plugability.DokkaPluginApiPreview
Expand All @@ -32,6 +34,12 @@ class AwsDokkaPlugin : DokkaPlugin() {
dokkaBase.htmlPreprocessors providing ::NoOpSearchbarDataInstaller override dokkaBase.baseSearchbarDataInstaller
}

val disablePlaygroundIntegration by extending {
CoreExtensions.pageTransformer providing ::DisablePlaygroundIntegration order {
after(dokkaBase.defaultSamplesTransformer)
}
}

@DokkaPluginApiPreview
override fun pluginApiPreviewAcknowledgement() = PluginApiPreviewAcknowledgement
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.sdk.kotlin.dokka.transformers

import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.pages.PageTransformer

@Suppress("UNUSED_PARAMETER") // `context` is required by the `provides` DSL method for installing transformers
class DisablePlaygroundIntegration(context: DokkaContext) : PageTransformer {
override fun invoke(input: RootPageNode) = input.transformContentPagesTree { page ->
page.modified(
content = page.content,
embeddedResources = page.embeddedResources.filterNot { "unpkg.com" in it },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import org.jetbrains.dokka.plugability.DokkaContext
class FilterInternalApis(context: DokkaContext) : SuppressedByConditionDocumentableFilterTransformer(context) {
override fun shouldBeSuppressed(d: Documentable): Boolean {
val isInternal = when (d) {
is DClass -> d.isInternalSdk()
is DObject -> d.isInternalSdk()
is DTypeAlias -> d.isInternalSdk()
is DFunction -> d.isInternalSdk()
is DProperty -> d.isInternalSdk()
is DEnum -> d.isInternalSdk()
is DEnumEntry -> d.isInternalSdk()
is DTypeParameter -> d.isInternalSdk()
is DClass -> d.isInternalSdk
is DObject -> d.isInternalSdk
is DTypeAlias -> d.isInternalSdk
is DFunction -> d.isInternalSdk
is DProperty -> d.isInternalSdk
is DEnum -> d.isInternalSdk
is DEnumEntry -> d.isInternalSdk
is DTypeParameter -> d.isInternalSdk
else -> false
}

Expand All @@ -33,12 +33,12 @@ class FilterInternalApis(context: DokkaContext) : SuppressedByConditionDocumenta
}
}

fun <T> T.isInternalSdk() where T : WithExtraProperties<out Documentable> =
internalAnnotation != null
private val internalAnnotationNames = setOf("InternalApi", "InternalSdkApi")

val <T> T.internalAnnotation where T : WithExtraProperties<out Documentable>
get() = extra[Annotations]?.let { annotations ->
annotations.directAnnotations.values.flatten().firstOrNull {
it.dri.toString() == "aws.sdk.kotlin.runtime/InternalSdkApi///PointingToDeclaration/"
}
}
private val <T> T.isInternalSdk: Boolean where T : WithExtraProperties<out Documentable>
get() = extra[Annotations]
?.directAnnotations
.orEmpty()
.values
.flatten()
.any { it.dri.classNames in internalAnnotationNames }

0 comments on commit 77014ed

Please sign in to comment.