Skip to content

Commit ab4bc94

Browse files
committed
pr feedbacks
1 parent f5656ef commit ab4bc94

File tree

4 files changed

+91
-78
lines changed

4 files changed

+91
-78
lines changed

build.gradle.kts

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ plugins {
2727
alias(libs.plugins.aws.kotlin.repo.tools.artifactsizemetrics)
2828
}
2929

30+
//subprojects {
31+
// apply(from = "${rootProject.file("buildSrc/src/main/kotlin/dokka-customization.gradle.kts")}")
32+
//}
33+
3034
artifactSizeMetrics {
3135
artifactPrefixes = setOf(":services", ":aws-runtime")
3236
closurePrefixes = setOf(":services")
@@ -41,6 +45,8 @@ val testJavaVersion = typedProp<String>("test.java.version")?.let {
4145
}
4246

4347
allprojects {
48+
apply(from = "${rootProject.file("buildSrc/src/main/kotlin/dokka-customization.gradle.kts")}")
49+
4450
tasks.withType<org.jetbrains.dokka.gradle.AbstractDokkaTask>().configureEach {
4551
val sdkVersion: String by project
4652
moduleVersion.set(sdkVersion)
@@ -122,83 +128,6 @@ allprojects {
122128
}
123129

124130
project.afterEvaluate {
125-
val trimNavigations = tasks.register("trimNavigations") {
126-
description = "Trims navigation files to remove unrelated child submenu"
127-
group = "documentation"
128-
129-
doLast {
130-
val dokkaOutputDir = rootProject.buildDir.resolve("dokka/htmlMultiModule")
131-
132-
if (!dokkaOutputDir.exists()) {
133-
logger.warn("Dokka output directory not found: ${dokkaOutputDir.absolutePath}")
134-
logger.warn("Skipping navigation trimming")
135-
return@doLast
136-
}
137-
138-
dokkaOutputDir.listFiles { file ->
139-
file.isDirectory && file.resolve("navigation.html").exists()
140-
}?.forEach { moduleDir ->
141-
val moduleName = moduleDir.name
142-
143-
val navFile = File(moduleDir, "navigation.html")
144-
145-
if (navFile.exists()) {
146-
val doc = Jsoup.parse(navFile, "UTF-8")
147-
148-
// Fix navigation links
149-
doc.select("a[href^='../']").forEach { anchor ->
150-
val originalHref = anchor.attr("href")
151-
val trimmedHref = originalHref.replace("../", "")
152-
anchor.attr("href", trimmedHref)
153-
}
154-
155-
val sideMenuParts = doc.select("div.sideMenu > div.sideMenuPart")
156-
157-
sideMenuParts.forEach { submenu ->
158-
val submenuId = submenu.id()
159-
// If this is not the current module's submenu, remove all its nested content
160-
if (submenuId != "$moduleName-nav-submenu") {
161-
val overviewDiv = submenu.select("> div.overview").first()
162-
overviewDiv?.select("span.navButton")?.remove()
163-
submenu.children().remove()
164-
if (overviewDiv != null) {
165-
submenu.appendChild(overviewDiv)
166-
}
167-
}
168-
}
169-
170-
val wrappedContent = "<div class=\"sideMenu\">\n${sideMenuParts.outerHtml()}\n</div>"
171-
navFile.writeText(wrappedContent)
172-
}
173-
}
174-
}
175-
}
176-
177-
val useCustomNavigations = tasks.register("useCustomNavigations") {
178-
group = "documentation"
179-
description = "Replace default Dokka navigation-loader.js with custom implementation"
180-
181-
doLast {
182-
val dokkaOutputDir = rootProject.buildDir.resolve("dokka/htmlMultiModule")
183-
184-
if (!dokkaOutputDir.exists()) {
185-
logger.warn("Dokka output directory not found: ${dokkaOutputDir.absolutePath}")
186-
logger.warn("Skipping using custom navigations")
187-
return@doLast
188-
}
189-
190-
dokkaOutputDir.walkTopDown()
191-
.filter { it.isFile && it.name.endsWith(".html") }
192-
.forEach { file ->
193-
val updatedContent = file.readLines().filterNot { line ->
194-
line.contains("""scripts/navigation-loader.js""")
195-
}.joinToString("\n")
196-
197-
file.writeText(updatedContent)
198-
}
199-
}
200-
}
201-
202131
// configure the root multimodule docs
203132
tasks.dokkaHtmlMultiModule.configure {
204133
moduleName.set("AWS SDK for Kotlin")
@@ -216,7 +145,7 @@ project.afterEvaluate {
216145
rootProject.file("docs/dokka-presets/README.md"),
217146
)
218147

219-
finalizedBy(trimNavigations, useCustomNavigations)
148+
finalizedBy("trimNavigations", "applyCustomNavigationLoader")
220149
}
221150
}
222151

buildSrc/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ plugins {
55
repositories {
66
mavenCentral()
77
}
8+
9+
dependencies {
10+
implementation(libs.jsoup)
11+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import org.jsoup.Jsoup
2+
3+
tasks.register("trimNavigations") {
4+
description = "Trims navigation files to remove unrelated child submenu"
5+
group = "documentation"
6+
7+
doLast {
8+
val dokkaOutputDir = rootProject.buildDir.resolve("dokka/htmlMultiModule")
9+
10+
if (!dokkaOutputDir.exists()) {
11+
logger.info("Dokka output directory not found at ${dokkaOutputDir.absolutePath}, skipping navigation trimming")
12+
return@doLast
13+
}
14+
15+
dokkaOutputDir.listFiles { file ->
16+
file.isDirectory && file.resolve("navigation.html").exists()
17+
}?.forEach { moduleDir ->
18+
println("trimming navigation for module ${moduleDir.name}")
19+
val moduleName = moduleDir.name
20+
21+
val navFile = File(moduleDir, "navigation.html")
22+
23+
val doc = Jsoup.parse(navFile, "UTF-8")
24+
25+
// Fix navigation links
26+
doc.select("a[href^='../']").forEach { anchor ->
27+
val originalHref = anchor.attr("href")
28+
val trimmedHref = originalHref.replace("../", "")
29+
anchor.attr("href", trimmedHref)
30+
}
31+
32+
val sideMenuParts = doc.select("div.sideMenu > div.sideMenuPart")
33+
34+
sideMenuParts.forEach { submenu ->
35+
val submenuId = submenu.id()
36+
// If this is not the current module's submenu, remove all its nested content
37+
if (submenuId != "$moduleName-nav-submenu") {
38+
val overviewDiv = submenu.select("> div.overview").first()
39+
overviewDiv?.select("span.navButton")?.remove()
40+
submenu.children().remove()
41+
if (overviewDiv != null) {
42+
submenu.appendChild(overviewDiv)
43+
}
44+
}
45+
}
46+
47+
val wrappedContent = "<div class=\"sideMenu\">\n${sideMenuParts.outerHtml()}\n</div>"
48+
navFile.writeText(wrappedContent)
49+
}
50+
}
51+
}
52+
53+
tasks.register("applyCustomNavigationLoader") {
54+
group = "documentation"
55+
description = "Replace default Dokka navigation-loader.js with custom implementation"
56+
57+
doLast {
58+
val dokkaOutputDir = rootProject.buildDir.resolve("dokka/htmlMultiModule")
59+
60+
if (!dokkaOutputDir.exists()) {
61+
logger.info("Dokka output directory not found at ${dokkaOutputDir.absolutePath}, skipping apply custom navigation loader")
62+
return@doLast
63+
}
64+
65+
dokkaOutputDir.walkTopDown()
66+
.filter { it.isFile && it.name.endsWith(".html") }
67+
.forEach { file ->
68+
val updatedContent = file.readLines().filterNot { line ->
69+
line.contains("""scripts/navigation-loader.js""")
70+
}.joinToString("\n")
71+
72+
file.writeText(updatedContent)
73+
}
74+
}
75+
}

docs/dokka-presets/scripts/custom-navigation-loader.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Custom navigation loader for AWS SDK for Kotlin documentation.
2+
13
// Extracts the module name from a given URL href
24
function extractModuleName(href) {
35
try{
@@ -56,6 +58,9 @@ function loadNavigation() {
5658

5759
navigationPageText = loadNavigation()
5860

61+
// =================================================================
62+
// Everything below this is copied from Dokka's navigation-loader.js
63+
// =================================================================
5964
displayNavigationFromPage = () => {
6065
navigationPageText.then(data => {
6166
document.getElementById("sideMenu").innerHTML = data;

0 commit comments

Comments
 (0)