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
  • Loading branch information
ianbotsf committed Sep 12, 2024
1 parent be6b82d commit 067481b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
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.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 },
)
}
}
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,10 @@ class FilterInternalApis(context: DokkaContext) : SuppressedByConditionDocumenta
}
}

fun <T> T.isInternalSdk() where T : WithExtraProperties<out Documentable> =
internalAnnotation != null

val <T> T.internalAnnotation where T : WithExtraProperties<out Documentable>
get() = extra[Annotations]?.let { annotations ->
annotations.directAnnotations.values.flatten().firstOrNull {
it.dri.toString() == "aws.smithy.kotlin.runtime.InternalApi///PointingToDeclaration/"
}
}
private val <T> T.isInternalSdk: Boolean where T : WithExtraProperties<out Documentable>
get() = extra[Annotations]
?.directAnnotations
.orEmpty()
.values
.flatten()
.any { it.dri.classNames == "InternalApi" }
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit 067481b

Please sign in to comment.