Kotlin / dokka

API documentation engine for Kotlin
https://kotl.in/dokka
Apache License 2.0
3.44k stars 410 forks source link

Generate README.md instead of index.md #333

Open msink opened 6 years ago

msink commented 6 years ago

Is it possible to generate README.md instead of index.md for each class, in github flavored markdown mode?

semoro commented 6 years ago

Right now it is not supported

joserobjr commented 5 years ago

This will do it:

task dokkaKdoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
    outputFormat = 'gfm'
    outputDirectory = "$buildDir/kdoc"
}

import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
task createReadmeFiles(dependsOn: dokkaKdoc) {
    doFirst {
        Files.walk(Paths.get(dokkaKdoc.outputDirectory))
                .filter { it.getFileName().toString().toLowerCase() == "index.md" }
                .forEach {
                    try {
                        Files.copy(it, it.resolveSibling("README.md"), StandardCopyOption.REPLACE_EXISTING)
                    } catch (e) {
                        throw new RuntimeException(e)
                    }
                }
    }
}

Just call createReadmeFiles instead of dokkaKdoc

atulgpt commented 3 years ago

@semoro/ @msink will this feature be supported in a future release?

tonisives commented 3 months ago

You can register this task that renames index.md to README.md after dokkaGfm finishes

build.gradle.kts

dokkaGfm {
    outputDirectory.set(file("$rootDir/docs/"))
}

tasks.register('renameDokkaReadme') {
    doLast {
        file("$rootDir/docs/index.md").renameTo("$rootDir/docs/README.md")
    }
}

tasks.dokkaGfm.finalizedBy renameDokkaReadme