aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin
diff options
context:
space:
mode:
authorOleg Yukhnevich <whyoleg@gmail.com>2023-11-07 15:27:34 +0200
committerGitHub <noreply@github.com>2023-11-07 15:27:34 +0200
commit64cce58f73f908909ba60da6005d7abb2572b2f0 (patch)
treeb66897df0bb86e159d6d040c65e04552efd1ee68 /plugins/base/src/main/kotlin
parent84e48b516500433332e9279237cd139f7836ca94 (diff)
downloaddokka-64cce58f73f908909ba60da6005d7abb2572b2f0.tar.gz
dokka-64cce58f73f908909ba60da6005d7abb2572b2f0.tar.bz2
dokka-64cce58f73f908909ba60da6005d7abb2572b2f0.zip
Add the link to GitHub repo to the header if there are source links defined (#3235)
* Use URL from base plugin configuration * Add integration test for the multi-module project that the homepage link exists everywhere
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r--plugins/base/src/main/kotlin/DokkaBaseConfiguration.kt3
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt1
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/innerTemplating/DefaultTemplateModelFactory.kt24
3 files changed, 22 insertions, 6 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBaseConfiguration.kt b/plugins/base/src/main/kotlin/DokkaBaseConfiguration.kt
index 11184126..34195f65 100644
--- a/plugins/base/src/main/kotlin/DokkaBaseConfiguration.kt
+++ b/plugins/base/src/main/kotlin/DokkaBaseConfiguration.kt
@@ -14,7 +14,8 @@ public data class DokkaBaseConfiguration(
var separateInheritedMembers: Boolean = separateInheritedMembersDefault,
var footerMessage: String = defaultFooterMessage,
var mergeImplicitExpectActualDeclarations: Boolean = mergeImplicitExpectActualDeclarationsDefault,
- var templatesDir: File? = defaultTemplatesDir
+ var templatesDir: File? = defaultTemplatesDir,
+ var homepageLink: String? = null,
) : ConfigurableBlock {
public companion object {
public val defaultFooterMessage: String = "© ${Year.now().value} Copyright"
diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
index dc877605..dad013e2 100644
--- a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
@@ -111,6 +111,7 @@ public object AssetsInstaller : PageTransformer {
"images/copy-successful-icon.svg",
"images/theme-toggle.svg",
"images/burger.svg",
+ "images/homepage.svg",
// navigation icons
"images/nav-icons/abstract-class.svg",
diff --git a/plugins/base/src/main/kotlin/renderers/html/innerTemplating/DefaultTemplateModelFactory.kt b/plugins/base/src/main/kotlin/renderers/html/innerTemplating/DefaultTemplateModelFactory.kt
index 3883bc4a..fe6f0089 100644
--- a/plugins/base/src/main/kotlin/renderers/html/innerTemplating/DefaultTemplateModelFactory.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/innerTemplating/DefaultTemplateModelFactory.kt
@@ -86,10 +86,16 @@ public class DefaultTemplateModelFactory(
return mapper
}
- override fun buildSharedModel(): TemplateMap = mapOf<String, Any>(
- "footerMessage" to (configuration?.footerMessage?.takeIf { it.isNotEmpty() }
- ?: DokkaBaseConfiguration.defaultFooterMessage)
- )
+ override fun buildSharedModel(): TemplateMap {
+ val mapper = mutableMapOf<String, Any>()
+
+ mapper["footerMessage"] =
+ (configuration?.footerMessage?.takeIf(String::isNotBlank) ?: DokkaBaseConfiguration.defaultFooterMessage)
+
+ configuration?.homepageLink?.takeIf(String::isNotBlank)?.let { mapper["homepageLink"] = it }
+
+ return mapper
+ }
private val DisplaySourceSet.comparableKey
get() = sourceSetIDs.merged.let { it.scopeId + it.sourceSetName }
@@ -107,6 +113,7 @@ public class DefaultTemplateModelFactory(
rel = LinkRel.stylesheet,
href = if (resource.isAbsolute) resource else "$pathToRoot$resource"
)
+
resource.URIExtension == "js" ->
script(
type = ScriptType.textJavaScript,
@@ -117,6 +124,7 @@ public class DefaultTemplateModelFactory(
else
async = true
}
+
resource.isImage() -> link(href = if (resource.isAbsolute) resource else "$pathToRoot$resource")
else -> null
}
@@ -125,6 +133,7 @@ public class DefaultTemplateModelFactory(
append(resourceHtml)
}
}
+
}
private class PrintDirective(val generateData: () -> String) : TemplateDirectiveModel {
@@ -144,7 +153,10 @@ private class PrintDirective(val generateData: () -> String) : TemplateDirective
}
}
-private class TemplateDirective(val configuration: DokkaConfiguration, val pathToRoot: String) : TemplateDirectiveModel {
+private class TemplateDirective(
+ val configuration: DokkaConfiguration,
+ val pathToRoot: String
+) : TemplateDirectiveModel {
override fun execute(
env: Environment,
params: MutableMap<Any?, Any?>?,
@@ -170,6 +182,7 @@ private class TemplateDirective(val configuration: DokkaConfiguration, val pathT
Context(env, body)
)
}
+
"projectName" -> {
body ?: throw TemplateModelException(
"No directive body $commandName command."
@@ -183,6 +196,7 @@ private class TemplateDirective(val configuration: DokkaConfiguration, val pathT
Context(env, body)
)
}
+
else -> throw TemplateModelException(
"The parameter $PARAM_NAME $commandName is unknown"
)