added extensive markdown rendering tests and Kotlin/JS externals for marked library
This commit is contained in:
1 parent
67e4d76f59
commit
f4d1a77496
10 files changed
+848
-20
No files matched your search
@@ -47,7 +47,17 @@ kotlin {
|
||||
dependencies {
|
||||
implementation("org.jetbrains.compose.runtime:runtime:1.9.3")
|
||||
implementation("org.jetbrains.compose.html:html-core:1.9.3")
|
||||
// Coroutines for JS (used for fetching docs)
|
||||
implementation(libs.kotlinx.coroutines.core)
|
||||
// Markdown parser (NPM)
|
||||
implementation(npm("marked", "12.0.2"))
|
||||
}
|
||||
// Serve project docs and images as static resources in the site
|
||||
resources.srcDir(rootProject.projectDir.resolve("docs"))
|
||||
resources.srcDir(rootProject.projectDir.resolve("images"))
|
||||
// Also include generated resources (e.g., docs index JSON)
|
||||
// Use Gradle's layout to properly reference the build directory provider
|
||||
resources.srcDir(layout.buildDirectory.dir("generated-resources"))
|
||||
}
|
||||
val jsTest by getting {
|
||||
dependencies {
|
||||
@@ -57,4 +67,62 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
// Generate an index of markdown documents under project /docs as a JSON array
|
||||
val generateDocsIndex by tasks.registering {
|
||||
group = "documentation"
|
||||
description = "Generates docs-index.json listing all Markdown files under /docs"
|
||||
|
||||
val docsDir = rootProject.projectDir.resolve("docs")
|
||||
val outDir = layout.buildDirectory.dir("generated-resources")
|
||||
|
||||
inputs.dir(docsDir)
|
||||
outputs.dir(outDir)
|
||||
|
||||
doLast {
|
||||
val docs = mutableListOf<String>()
|
||||
if (docsDir.exists()) {
|
||||
docsDir.walkTopDown()
|
||||
.filter { it.isFile && it.extension.equals("md", ignoreCase = true) }
|
||||
.forEach { f ->
|
||||
val rel = docsDir.toPath().relativize(f.toPath()).toString()
|
||||
.replace('\\', '/')
|
||||
// store paths relative to site root, e.g. "docs/Iterator.md"
|
||||
docs += "docs/$rel"
|
||||
}
|
||||
}
|
||||
val out = outDir.get().asFile
|
||||
out.mkdirs()
|
||||
val file = out.resolve("docs-index.json")
|
||||
val json = buildString {
|
||||
append('[')
|
||||
docs.forEachIndexed { i, s ->
|
||||
if (i > 0) append(',')
|
||||
append('"').append(s.replace("\"", "\\\""))
|
||||
.append('"')
|
||||
}
|
||||
append(']')
|
||||
}
|
||||
file.writeText(json)
|
||||
println("Generated ${'$'}{file.absolutePath} with ${'$'}{docs.size} entries")
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure any ProcessResources task depends on docs index generation so the JSON is packaged
|
||||
tasks.configureEach {
|
||||
if (name.endsWith("ProcessResources")) {
|
||||
dependsOn(generateDocsIndex)
|
||||
}
|
||||
}
|
||||
|
||||
// Also make common dev/prod tasks depend on docs index generation to avoid 404 during dev server
|
||||
listOf(
|
||||
"browserDevelopmentRun",
|
||||
"browserProductionWebpack",
|
||||
"jsProcessResources"
|
||||
).forEach { taskName ->
|
||||
tasks.matching { it.name == taskName }.configureEach {
|
||||
dependsOn(generateDocsIndex)
|
||||
}
|
||||
}
|
||||
|
||||
// Optional: configure toolchain if needed by the project; uses root Kotlin version from version catalog
|
||||
Reference in new issue
Block a user