Skip to content

Commit 7afa0ea

Browse files
authored
fix: stop including playground.js in Dokka pages and correctly filter for internal APIs (#1149)
1 parent cbf98f7 commit 7afa0ea

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.smithy.kotlin.dokka
6+
7+
import org.jetbrains.dokka.pages.RootPageNode
8+
import org.jetbrains.dokka.plugability.DokkaContext
9+
import org.jetbrains.dokka.transformers.pages.PageTransformer
10+
11+
@Suppress("UNUSED_PARAMETER") // `context` is required by the `provides` DSL method for installing transformers
12+
class DisablePlaygroundIntegration(context: DokkaContext) : PageTransformer {
13+
override fun invoke(input: RootPageNode) = input.transformContentPagesTree { page ->
14+
page.modified(
15+
content = page.content,
16+
embeddedResources = page.embeddedResources.filterNot { "unpkg.com" in it },
17+
)
18+
}
19+
}

dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/FilterInternalApis.kt

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import org.jetbrains.dokka.plugability.DokkaContext
1616
class FilterInternalApis(context: DokkaContext) : SuppressedByConditionDocumentableFilterTransformer(context) {
1717
override fun shouldBeSuppressed(d: Documentable): Boolean {
1818
val isInternal = when (d) {
19-
is DClass -> d.isInternalSdk()
20-
is DObject -> d.isInternalSdk()
21-
is DTypeAlias -> d.isInternalSdk()
22-
is DFunction -> d.isInternalSdk()
23-
is DProperty -> d.isInternalSdk()
24-
is DEnum -> d.isInternalSdk()
25-
is DEnumEntry -> d.isInternalSdk()
26-
is DTypeParameter -> d.isInternalSdk()
19+
is DClass -> d.isInternalSdk
20+
is DObject -> d.isInternalSdk
21+
is DTypeAlias -> d.isInternalSdk
22+
is DFunction -> d.isInternalSdk
23+
is DProperty -> d.isInternalSdk
24+
is DEnum -> d.isInternalSdk
25+
is DEnumEntry -> d.isInternalSdk
26+
is DTypeParameter -> d.isInternalSdk
2727
else -> false
2828
}
2929

@@ -33,12 +33,10 @@ class FilterInternalApis(context: DokkaContext) : SuppressedByConditionDocumenta
3333
}
3434
}
3535

36-
fun <T> T.isInternalSdk() where T : WithExtraProperties<out Documentable> =
37-
internalAnnotation != null
38-
39-
val <T> T.internalAnnotation where T : WithExtraProperties<out Documentable>
40-
get() = extra[Annotations]?.let { annotations ->
41-
annotations.directAnnotations.values.flatten().firstOrNull {
42-
it.dri.toString() == "aws.smithy.kotlin.runtime.InternalApi///PointingToDeclaration/"
43-
}
44-
}
36+
private val <T> T.isInternalSdk: Boolean where T : WithExtraProperties<out Documentable>
37+
get() = extra[Annotations]
38+
?.directAnnotations
39+
.orEmpty()
40+
.values
41+
.flatten()
42+
.any { it.dri.classNames == "InternalApi" }

dokka-smithy/src/main/kotlin/aws/smithy/kotlin/dokka/SmithyDokkaPlugin.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package aws.smithy.kotlin.dokka
77

8+
import org.jetbrains.dokka.CoreExtensions
89
import org.jetbrains.dokka.base.DokkaBase
910
import org.jetbrains.dokka.plugability.DokkaPlugin
1011
import org.jetbrains.dokka.plugability.DokkaPluginApiPreview
@@ -30,6 +31,12 @@ class SmithyDokkaPlugin : DokkaPlugin() {
3031
dokkaBase.htmlPreprocessors providing ::NoOpSearchbarDataInstaller override dokkaBase.baseSearchbarDataInstaller
3132
}
3233

34+
val disablePlaygroundIntegration by extending {
35+
CoreExtensions.pageTransformer providing ::DisablePlaygroundIntegration order {
36+
after(dokkaBase.defaultSamplesTransformer)
37+
}
38+
}
39+
3340
@OptIn(DokkaPluginApiPreview::class)
3441
override fun pluginApiPreviewAcknowledgement() = PluginApiPreviewAcknowledgement
3542
}

0 commit comments

Comments
 (0)