aboutsummaryrefslogtreecommitdiff
path: root/dokka-subprojects/plugin-versioning/src/main/kotlin/org/jetbrains/dokka/versioning/VersioningConfiguration.kt
blob: 91b1117d2cc6c9c10c187843f85e1e2e3cfc10f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package org.jetbrains.dokka.versioning

import org.jetbrains.dokka.plugability.ConfigurableBlock
import org.jetbrains.dokka.plugability.DokkaContext
import java.io.File

public data class VersioningConfiguration(
    var olderVersionsDir: File? = defaultOlderVersionsDir,
    var olderVersions: List<File>? = defaultOlderVersions,
    var versionsOrdering: List<String>? = defaultVersionsOrdering,
    var version: String? = defaultVersion,
    var renderVersionsNavigationOnAllPages: Boolean? = defaultRenderVersionsNavigationOnAllPages
) : ConfigurableBlock {
    internal fun versionFromConfigurationOrModule(dokkaContext: DokkaContext): String =
        version ?: dokkaContext.configuration.moduleVersion ?: "1.0"

    internal fun allOlderVersions(): List<File> {
        if (olderVersionsDir != null)
            assert(olderVersionsDir!!.isDirectory) { "Supplied previous version $olderVersionsDir is not a directory!" }

        return olderVersionsDir?.listFiles()?.toList().orEmpty() + olderVersions.orEmpty()
    }

    public companion object {
        public val defaultOlderVersionsDir: File? = null
        public val defaultOlderVersions: List<File>? = null
        public val defaultVersionsOrdering: List<String>? = null
        public val defaultVersion: String? = null
        public val defaultRenderVersionsNavigationOnAllPages: Boolean = true

        public const val OLDER_VERSIONS_DIR: String = "older"
        public const val VERSIONS_FILE: String = "version.json"
    }
}