Skip to content

Commit 4cec8d3

Browse files
committed
Trimmed navigation and external docs samples are working
1 parent 2c99ce3 commit 4cec8d3

File tree

4 files changed

+313
-258
lines changed

4 files changed

+313
-258
lines changed

build.gradle.kts

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -38,69 +38,6 @@ val testJavaVersion = typedProp<String>("test.java.version")?.let {
3838
}
3939

4040
allprojects {
41-
// apply(from = "${rootProject.file("buildSrc/src/main/kotlin/dokka-customization.gradle.kts")}")
42-
//
43-
// tasks.withType<org.jetbrains.dokka.gradle.AbstractDokkaTask>().configureEach {
44-
// val sdkVersion: String by project
45-
// moduleVersion.set(sdkVersion)
46-
//
47-
// val year = java.time.LocalDate.now().year
48-
// val pluginConfigMap = mapOf(
49-
// "org.jetbrains.dokka.base.DokkaBase" to """
50-
// {
51-
// "customStyleSheets": [
52-
// "${rootProject.file("docs/dokka-presets/css/logo-styles.css")}",
53-
// "${rootProject.file("docs/dokka-presets/css/aws-styles.css")}"
54-
// ],
55-
// "customAssets": [
56-
// "${rootProject.file("docs/dokka-presets/assets/logo-icon.svg")}",
57-
// "${rootProject.file("docs/dokka-presets/assets/aws_logo_white_59x35.png")}",
58-
// "${rootProject.file("docs/dokka-presets/scripts/accessibility.js")}",
59-
// "${rootProject.file("docs/dokka-presets/scripts/custom-navigation-loader.js")}"
60-
// ],
61-
// "footerMessage": "© $year, Amazon Web Services, Inc. or its affiliates. All rights reserved.",
62-
// "separateInheritedMembers" : true,
63-
// "templatesDir": "${rootProject.file("docs/dokka-presets/templates")}"
64-
// }
65-
// """,
66-
// )
67-
// pluginsMapConfiguration.set(pluginConfigMap)
68-
// }
69-
//
70-
// tasks.withType<org.jetbrains.dokka.gradle.DokkaTaskPartial>().configureEach {
71-
// dokkaSourceSets.configureEach {
72-
// samples.from(project.file("samples").path, project.file("generated-src/samples").path)
73-
//
74-
// // Each module can include their own top-level module documentation in one or more included Markdown files,
75-
// // each of which must begin with `# Module <module-name>` where <module-name> is the literal name of the
76-
// // Gradle module. See https://kotlinlang.org/docs/dokka-module-and-package-docs.html for more details.
77-
// val includeFiles = setOf(
78-
// "OVERVIEW.md", // Auto-generated by ModuleDocumentationIntegration
79-
// "DOCS.md", // Hand-written docs explaining a module in greater detail
80-
// "API.md", // Auto-generated by `kat` tool
81-
// ).mapNotNull { project.file(it).takeIf { it.exists() } }
82-
// includes.from(includeFiles)
83-
// }
84-
//
85-
// val smithyKotlinPackageListUrl: String? by project
86-
// val smithyKotlinDocBaseUrl: String? by project
87-
//
88-
// // Configure Dokka to link to smithy-kotlin types if specified in properties
89-
// // These optional properties are supplied api the api docs build job but are unneeded otherwise
90-
// smithyKotlinDocBaseUrl.takeUnless { it.isNullOrEmpty() }?.let { docBaseUrl ->
91-
// val expandedDocBaseUrl = docBaseUrl.replace("\$smithyKotlinRuntimeVersion", libs.versions.smithy.kotlin.runtime.version.get())
92-
// dokkaSourceSets.configureEach {
93-
// externalDocumentationLink {
94-
// url.set(URL(expandedDocBaseUrl))
95-
//
96-
// smithyKotlinPackageListUrl
97-
// .takeUnless { it.isNullOrEmpty() }
98-
// ?.let { packageListUrl.set(URL(it)) }
99-
// }
100-
// }
101-
// }
102-
// }
103-
10441
if (rootProject.typedProp<Boolean>("kotlinWarningsAsErrors") == true) {
10542
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
10643
compilerOptions.allWarningsAsErrors = true
@@ -133,29 +70,6 @@ dokka {
13370
}
13471
}
13572

136-
137-
//project.afterEvaluate {
138-
// // configure the root multimodule docs
139-
// tasks.dokkaHtmlMultiModule.configure {
140-
// moduleName.set("AWS SDK for Kotlin")
141-
//
142-
// // Output subprojects' docs to <docs-base>/project-name/* instead of <docs-base>/path/to/project-name/*
143-
// // This is especially important for inter-repo linking (e.g., via externalDocumentationLink) because the
144-
// // package-list doesn't contain enough project path information to indicate where modules' documentation are
145-
// // located.
146-
// fileLayout.set { parent, child ->
147-
// parent.outputDirectory.dir(child.moduleName)
148-
// }
149-
//
150-
// includes.from(
151-
// // NOTE: these get concatenated
152-
// rootProject.file("docs/dokka-presets/README.md"),
153-
// )
154-
//
155-
// finalizedBy("trimNavigations", "applyCustomNavigationLoader")
156-
// }
157-
//}
158-
15973
// Aggregate subprojects' documentation
16074
dependencies {
16175
dokka(project(":aws-runtime"))

buildSrc/src/main/kotlin/dokka-convention.gradle.kts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import kotlin.text.set
1+
import org.jsoup.Jsoup
2+
import kotlin.io.path.ExperimentalPathApi
3+
import kotlin.io.path.PathWalkOption
4+
import kotlin.io.path.exists
5+
import kotlin.io.path.isDirectory
6+
import kotlin.io.path.name
7+
import kotlin.io.path.walk
28

39
plugins {
410
id("org.jetbrains.dokka")
@@ -20,6 +26,7 @@ dokka {
2026
customAssets.from(
2127
rootProject.file("docs/dokka-presets/assets/logo-icon.svg"),
2228
rootProject.file("docs/dokka-presets/scripts/accessibility.js"),
29+
rootProject.file("docs/dokka-presets/scripts/custom-navigation-loader.js"),
2330
)
2431

2532
templatesDir.set(rootProject.file("docs/dokka-presets/templates"))
@@ -42,6 +49,16 @@ dokka {
4249
if (name == "commonMain") {
4350
samples.from(project.file("samples").path, project.file("generated-src/samples").path)
4451
}
52+
53+
// Each module can include their own top-level module documentation in one or more included Markdown files,
54+
// each of which must begin with `# Module <module-name>` where <module-name> is the literal name of the
55+
// Gradle module. See https://kotlinlang.org/docs/dokka-module-and-package-docs.html for more details.
56+
val includeFiles = setOf(
57+
"OVERVIEW.md", // Auto-generated by ModuleDocumentationIntegration
58+
"DOCS.md", // Hand-written docs explaining a module in greater detail
59+
"API.md", // Auto-generated by `kat` tool
60+
).mapNotNull { project.file(it).takeIf { it.exists() } }
61+
includes.from(includeFiles)
4562
}
4663

4764
// Configure Dokka to link to smithy-kotlin types
@@ -58,3 +75,41 @@ dokka {
5875
dependencies {
5976
dokkaPlugin(project(":dokka-aws"))
6077
}
78+
79+
tasks.register("trimNavigations") {
80+
description = "Trims navigation.html files to remove unrelated projects' side menus"
81+
group = "documentation"
82+
83+
doLast {
84+
val dokkaOutputDir = layout.buildDirectory.get().dir("dokka/html").asFile.toPath()
85+
86+
if (!dokkaOutputDir.exists()) {
87+
logger.info("Dokka output directory not found at ${dokkaOutputDir.toAbsolutePath()}, skipping navigation trimming")
88+
return@doLast
89+
}
90+
91+
@OptIn(ExperimentalPathApi::class)
92+
dokkaOutputDir.walk(PathWalkOption.INCLUDE_DIRECTORIES)
93+
.filter { it.isDirectory() && it.resolve("navigation.html").exists() }
94+
.forEach { moduleDir ->
95+
val moduleName = moduleDir.name
96+
97+
val navigation = moduleDir.resolve("navigation.html").toFile()
98+
val doc = Jsoup.parse(navigation)
99+
100+
// Trim side menus
101+
doc.select("div.sideMenu > div.toc--part")
102+
.filterNot { it.id().startsWith("$moduleName-nav-submenu") }
103+
.forEach { it.remove() }
104+
105+
// Update navigation.html
106+
val trimmedSideMenuParts = doc.select("div.sideMenu > div.toc--part")
107+
navigation.writeText("<div class=\"sideMenu\">\n$trimmedSideMenuParts\n</div>")
108+
}
109+
}
110+
}
111+
112+
tasks.dokkaGenerate {
113+
finalizedBy("trimNavigations")
114+
}
115+

buildSrc/src/main/kotlin/dokka-customization.gradle.kts

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)