From 067481be5fbb21ede9ea69217be07457df130be8 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Thu, 12 Sep 2024 19:53:36 +0000 Subject: [PATCH] fix: stop including playground.js in Dokka pages and correctly filter for internal APIs --- .../dokka/DisablePlaygroundIntegration.kt | 19 +++++++++++ .../smithy/kotlin/dokka/FilterInternalApis.kt | 32 +++++++++---------- .../smithy/kotlin/dokka/SmithyDokkaPlugin.kt | 7 ++++ 3 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/DisablePlaygroundIntegration.kt diff --git a/dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/DisablePlaygroundIntegration.kt b/dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/DisablePlaygroundIntegration.kt new file mode 100644 index 000000000..fd83f0b7a --- /dev/null +++ b/dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/DisablePlaygroundIntegration.kt @@ -0,0 +1,19 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.smithy.kotlin.dokka + +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-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/FilterInternalApis.kt b/dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/FilterInternalApis.kt index 164117fea..b92f091f0 100644 --- a/dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/FilterInternalApis.kt +++ b/dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/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,10 @@ class FilterInternalApis(context: DokkaContext) : SuppressedByConditionDocumenta } } -fun T.isInternalSdk() where T : WithExtraProperties = - internalAnnotation != null - -val T.internalAnnotation where T : WithExtraProperties - get() = extra[Annotations]?.let { annotations -> - annotations.directAnnotations.values.flatten().firstOrNull { - it.dri.toString() == "aws.smithy.kotlin.runtime.InternalApi///PointingToDeclaration/" - } - } +private val T.isInternalSdk: Boolean where T : WithExtraProperties + get() = extra[Annotations] + ?.directAnnotations + .orEmpty() + .values + .flatten() + .any { it.dri.classNames == "InternalApi" } diff --git a/dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/SmithyDokkaPlugin.kt b/dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/SmithyDokkaPlugin.kt index f3d440961..6971369db 100644 --- a/dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/SmithyDokkaPlugin.kt +++ b/dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/SmithyDokkaPlugin.kt @@ -5,6 +5,7 @@ package aws.smithy.kotlin.dokka +import org.jetbrains.dokka.CoreExtensions import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.plugability.DokkaPluginApiPreview @@ -30,6 +31,12 @@ class SmithyDokkaPlugin : DokkaPlugin() { dokkaBase.htmlPreprocessors providing ::NoOpSearchbarDataInstaller override dokkaBase.baseSearchbarDataInstaller } + val disablePlaygroundIntegration by extending { + CoreExtensions.pageTransformer providing ::DisablePlaygroundIntegration order { + after(dokkaBase.defaultSamplesTransformer) + } + } + @OptIn(DokkaPluginApiPreview::class) override fun pluginApiPreviewAcknowledgement() = PluginApiPreviewAcknowledgement }