From 81c82e8f0baddbf379fefab3bba4a15fd0c66a39 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Thu, 12 Sep 2024 19:54:04 +0000 Subject: [PATCH] fix: stop including playground.js in Dokka pages and correctly filter for internal APIs --- .../aws/sdk/kotlin/dokka/AwsDokkaPlugin.kt | 8 +++++ .../DisablePlaygroundIntegration.kt | 19 +++++++++++ .../dokka/transformers/FilterInternalApis.kt | 32 +++++++++---------- 3 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 dokka-aws/src/main/kotlin/aws/sdk/kotlin/dokka/transformers/DisablePlaygroundIntegration.kt diff --git a/dokka-aws/src/main/kotlin/aws/sdk/kotlin/dokka/AwsDokkaPlugin.kt b/dokka-aws/src/main/kotlin/aws/sdk/kotlin/dokka/AwsDokkaPlugin.kt index 1e0dbad589f..15cb08467fd 100644 --- a/dokka-aws/src/main/kotlin/aws/sdk/kotlin/dokka/AwsDokkaPlugin.kt +++ b/dokka-aws/src/main/kotlin/aws/sdk/kotlin/dokka/AwsDokkaPlugin.kt @@ -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 @@ -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 } diff --git a/dokka-aws/src/main/kotlin/aws/sdk/kotlin/dokka/transformers/DisablePlaygroundIntegration.kt b/dokka-aws/src/main/kotlin/aws/sdk/kotlin/dokka/transformers/DisablePlaygroundIntegration.kt new file mode 100644 index 00000000000..e56e832a4de --- /dev/null +++ b/dokka-aws/src/main/kotlin/aws/sdk/kotlin/dokka/transformers/DisablePlaygroundIntegration.kt @@ -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 }, + ) + } +} diff --git a/dokka-aws/src/main/kotlin/aws/sdk/kotlin/dokka/transformers/FilterInternalApis.kt b/dokka-aws/src/main/kotlin/aws/sdk/kotlin/dokka/transformers/FilterInternalApis.kt index 4e85b680a65..5e546d77156 100644 --- a/dokka-aws/src/main/kotlin/aws/sdk/kotlin/dokka/transformers/FilterInternalApis.kt +++ b/dokka-aws/src/main/kotlin/aws/sdk/kotlin/dokka/transformers/FilterInternalApis.kt @@ -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 } @@ -33,12 +33,12 @@ class FilterInternalApis(context: DokkaContext) : SuppressedByConditionDocumenta } } -fun T.isInternalSdk() where T : WithExtraProperties = - internalAnnotation != null +private val internalAnnotationNames = setOf("InternalApi", "InternalSdkApi") -val T.internalAnnotation where T : WithExtraProperties - get() = extra[Annotations]?.let { annotations -> - annotations.directAnnotations.values.flatten().firstOrNull { - it.dri.toString() == "aws.sdk.kotlin.runtime/InternalSdkApi///PointingToDeclaration/" - } - } +private val T.isInternalSdk: Boolean where T : WithExtraProperties + get() = extra[Annotations] + ?.directAnnotations + .orEmpty() + .values + .flatten() + .any { it.dri.classNames in internalAnnotationNames }