aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2021-08-25 14:54:34 +0200
committerGitHub <noreply@github.com>2021-08-25 14:54:34 +0200
commit742f96bdf5c0b842e68dfaf43f4ab3446e87e3df (patch)
tree8c8553f21f8175f298ace4005973d482b1f0be13 /plugins/base/src/main/kotlin
parent06650909dbce632bd92d3a10c2887b69555edbfc (diff)
downloaddokka-742f96bdf5c0b842e68dfaf43f4ab3446e87e3df.tar.gz
dokka-742f96bdf5c0b842e68dfaf43f4ab3446e87e3df.tar.bz2
dokka-742f96bdf5c0b842e68dfaf43f4ab3446e87e3df.zip
Dark mode (#2081)
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r--plugins/base/src/main/kotlin/DokkaBase.kt4
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt14
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt33
3 files changed, 15 insertions, 36 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt
index c0e512c5..7bc2912c 100644
--- a/plugins/base/src/main/kotlin/DokkaBase.kt
+++ b/plugins/base/src/main/kotlin/DokkaBase.kt
@@ -205,10 +205,6 @@ class DokkaBase : DokkaPlugin() {
htmlPreprocessors providing ::NavigationPageInstaller order { after(rootCreator) }
}
- val navigationSearchInstaller by extending {
- htmlPreprocessors providing ::NavigationSearchInstaller order { after(rootCreator) }
- }
-
val scriptsInstaller by extending {
htmlPreprocessors providing ::ScriptsInstaller order { after(rootCreator) }
}
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index 3086b82d..3cf914ce 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -758,6 +758,14 @@ open class HtmlRenderer(
templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) {
script { unsafe { +"""var pathToRoot = "###";""" } }
}
+ // This script doesn't need to be there but it is nice to have since app in dark mode doesn't 'blink' (class is added before it is rendered)
+ script { unsafe { +"""
+ const storage = localStorage.getItem("dokka-dark-mode")
+ const savedDarkMode = storage ? JSON.parse(storage) : false
+ if(savedDarkMode === true){
+ document.getElementsByTagName("html")[0].classList.add("theme-dark")
+ }
+ """.trimIndent() } }
resources.forEach {
when {
it.substringBefore('?').substringAfterLast('.') == "css" ->
@@ -808,6 +816,12 @@ open class HtmlRenderer(
}
div("pull-right d-flex") {
filterButtons(page)
+ button {
+ id = "theme-toggle-button"
+ span {
+ id = "theme-toggle"
+ }
+ }
div {
id = "searchBar"
}
diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
index 992c5eba..9faf4d17 100644
--- a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
@@ -49,37 +49,6 @@ abstract class NavigationDataProvider {
}
}
-open class NavigationSearchInstaller(val context: DokkaContext) : NavigationDataProvider(), PageTransformer {
- private val mapper = jacksonObjectMapper()
-
- open fun createSearchRecordFromNode(node: NavigationNode, location: String): SearchRecord =
- SearchRecord(name = node.name, location = location)
-
- override fun invoke(input: RootPageNode): RootPageNode {
- val page = RendererSpecificResourcePage(
- name = "scripts/navigation-pane.json",
- children = emptyList(),
- strategy = RenderingStrategy.DriLocationResolvableWrite { resolver ->
- val content = navigableChildren(input).withDescendants().map {
- createSearchRecordFromNode(it, resolveLocation(resolver, it.dri, it.sourceSets).orEmpty())
- }
- if (context.configuration.delayTemplateSubstitution) {
- mapper.writeValueAsString(AddToSearch(context.configuration.moduleName, content.toList()))
- } else {
- mapper.writeValueAsString(content)
- }
- })
-
- return input.modified(children = input.children + page)
- }
-
- private fun resolveLocation(locationResolver: DriResolver, dri: DRI, sourceSets: Set<DisplaySourceSet>): String? =
- locationResolver(dri, sourceSets).also { location ->
- if (location.isNullOrBlank()) context.logger.warn("Cannot resolve path for $dri and sourceSets: ${sourceSets.joinToString { it.name }}")
- }
-
-}
-
open class NavigationPageInstaller(val context: DokkaContext) : NavigationDataProvider(), PageTransformer {
override fun invoke(input: RootPageNode): RootPageNode =
@@ -152,13 +121,13 @@ class StylesInstaller(private val dokkaContext: DokkaContext) : PageTransformer
object AssetsInstaller : PageTransformer {
private val imagesPages = listOf(
"images/arrow_down.svg",
- "images/arrow_down_white.svg",
"images/logo-icon.svg",
"images/go-to-top-icon.svg",
"images/footer-go-to-link.svg",
"images/anchor-copy-button.svg",
"images/copy-icon.svg",
"images/copy-successful-icon.svg",
+ "images/theme-toggle.svg",
)
override fun invoke(input: RootPageNode) = input.modified(