Skip to content

Commit eea5086

Browse files
authored
feat: add analytic to smithy kotlin api ref docs (#1278)
* add analytic to smithy kotlin api ref docs * style
1 parent b6a032c commit eea5086

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

docs/dokka-presets/templates/base.ftl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<head>
88
<meta name="viewport" content="width=device-width, initial-scale=1" charset="UTF-8">
99
<@page_metadata.display/>
10+
<#-- AWS Analytics tracking script - Implements site-wide analytics and tracking functionality -->
11+
<script src="https://a0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"></script>
1012
<@template_cmd name="pathToRoot"><script>var pathToRoot = "${pathToRoot}";</script></@template_cmd>
1113
<script>document.documentElement.classList.replace("no-js","js");</script>
1214
<#-- This script doesn't need to be there but it is nice to have
@@ -24,6 +26,16 @@
2426
}
2527
}
2628
</script>
29+
<#-- Scripts for onboarding AWS Shortbread - Manages cookie consent banners and user preferences to help ensure
30+
compliance with privacy regulations like GDPR -->
31+
<script>var existingShortbreadEl = document.getElementById("awsccc-sb-ux-c");
32+
existingShortbreadEl && existingShortbreadEl.remove();
33+
</script>
34+
<script src="https://prod.assets.shortbread.aws.dev/shortbread.js"></script>
35+
<link href="https://prod.assets.shortbread.aws.dev/shortbread.css" rel="stylesheet">
36+
<script>const shortbread = AWSCShortbread();
37+
shortbread.checkForCookieConsent();
38+
</script>
2739
<#-- Resources (scripts, stylesheets) are handled by Dokka.
2840
Use customStyleSheets and customAssets to change them. -->
2941
<@resources/>

dokka-smithy/build.gradle.kts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
6+
import java.time.LocalDate
67

78
/*
89
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
910
* SPDX-License-Identifier: Apache-2.0
1011
*/
1112
plugins {
13+
alias(libs.plugins.dokka)
1214
alias(libs.plugins.kotlin.jvm)
1315
}
1416

@@ -17,6 +19,16 @@ description = "Custom Dokka plugin for Kotlin Smithy SDK API docs"
1719
dependencies {
1820
compileOnly(libs.dokka.base)
1921
compileOnly(libs.dokka.core)
22+
23+
testImplementation(libs.jsoup)
24+
testImplementation(libs.junit.jupiter)
25+
testImplementation(libs.kotest.assertions.core.jvm)
26+
testImplementation(libs.kotlin.test.junit5)
27+
}
28+
29+
tasks.test {
30+
useJUnitPlatform()
31+
dependsOn(tasks.dokkaHtml)
2032
}
2133

2234
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
@@ -30,3 +42,29 @@ tasks.withType<JavaCompile> {
3042
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
3143
targetCompatibility = JavaVersion.VERSION_1_8.toString()
3244
}
45+
46+
tasks.withType<org.jetbrains.dokka.gradle.AbstractDokkaTask>().configureEach {
47+
val sdkVersion: String by project
48+
moduleVersion.set(sdkVersion)
49+
50+
val year = LocalDate.now().year
51+
val pluginConfigMap = mapOf(
52+
"org.jetbrains.dokka.base.DokkaBase" to """
53+
{
54+
"customStyleSheets": [
55+
"${rootProject.file("docs/dokka-presets/css/logo-styles.css").absolutePath.replace("\\", "/")}",
56+
"${rootProject.file("docs/dokka-presets/css/aws-styles.css").absolutePath.replace("\\", "/")}"
57+
],
58+
"customAssets": [
59+
"${rootProject.file("docs/dokka-presets/assets/logo-icon.svg").absolutePath.replace("\\", "/")}",
60+
"${rootProject.file("docs/dokka-presets/assets/aws_logo_white_59x35.png").absolutePath.replace("\\", "/")}",
61+
"${rootProject.file("docs/dokka-presets/scripts/accessibility.js").absolutePath.replace("\\", "/")}"
62+
],
63+
"footerMessage": "© $year, Amazon Web Services, Inc. or its affiliates. All rights reserved.",
64+
"separateInheritedMembers" : true,
65+
"templatesDir": "${rootProject.file("docs/dokka-presets/templates").absolutePath.replace("\\", "/")}"
66+
}
67+
""",
68+
)
69+
pluginsMapConfiguration.set(pluginConfigMap)
70+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.jsoup.Jsoup
8+
import org.junit.jupiter.api.Test
9+
import org.junit.jupiter.api.TestInstance
10+
import java.io.File
11+
import kotlin.test.assertTrue
12+
13+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
14+
class DokkaSmithyTest {
15+
@Test
16+
fun testLoadScripts() {
17+
val testFile = File("build/dokka/html/index.html")
18+
19+
assertTrue(
20+
testFile.exists(),
21+
"Test file does not exist: ${testFile.absolutePath}",
22+
)
23+
24+
val document = Jsoup.parse(testFile, "UTF-8")
25+
26+
val expectedScripts = listOf(
27+
"awshome_s_code.js",
28+
)
29+
30+
val scripts = document.head().select("script[src]")
31+
32+
expectedScripts.forEach { expectedScript ->
33+
assertTrue(
34+
scripts.any { it.attr("src").endsWith(expectedScript) },
35+
"Expected script $expectedScript not found",
36+
)
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)