diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2020-10-05 10:24:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-05 10:24:06 +0200 |
commit | 49d4757acd8e6ef974baccbb228a76ceb74b59b0 (patch) | |
tree | 09ff129568a53a833476763da1c93910e470fc15 /plugins/base/src/main | |
parent | 249556460973007de3d436ddda1df7d100aefab0 (diff) | |
download | dokka-49d4757acd8e6ef974baccbb228a76ceb74b59b0.tar.gz dokka-49d4757acd8e6ef974baccbb228a76ceb74b59b0.tar.bz2 dokka-49d4757acd8e6ef974baccbb228a76ceb74b59b0.zip |
Render react resources as separate css to allow overriding (#1416)
* Render react resources as separate css to allow overriding
* Improve build.gradle.kts
Diffstat (limited to 'plugins/base/src/main')
3 files changed, 60 insertions, 26 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index bc2827ac..be3c09b9 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -202,12 +202,16 @@ class DokkaBase : DokkaPlugin() { htmlPreprocessors with SearchPageInstaller order { after(rootCreator) } } - val resourceInstaller by extending { - htmlPreprocessors with ResourceInstaller order { after(rootCreator) } + val scriptsInstaller by extending { + htmlPreprocessors with ScriptsInstaller order { after(rootCreator) } } - val styleAndScriptsAppender by extending { - htmlPreprocessors with StyleAndScriptsAppender order { after(rootCreator) } + val stylesInstaller by extending { + htmlPreprocessors with StylesInstaller order { after(rootCreator) } + } + + val assetsInstaller by extending { + htmlPreprocessors with AssetsInstaller order { after(rootCreator) } } val packageListCreator by extending { diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 3eb1c030..6bdeae62 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -682,6 +682,7 @@ open class HtmlRenderer( else -> unsafe { +it } } } + link(rel = LinkRel.stylesheet, href = page.root("styles/main.css")) {} script { unsafe { +"""var pathToRoot = "${locationProvider.pathToRoot(page)}";""" } } } body { diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt index 1afb5569..a5fca92f 100644 --- a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt +++ b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt @@ -62,7 +62,8 @@ object NavigationPageInstaller : PageTransformer { name = "scripts/navigation-pane.json", children = emptyList(), strategy = RenderingStrategy.LocationResolvableWrite { resolver -> - mapper.writeValueAsString(nodes.withDescendants().map { NavigationNodeView.from(it, resolver(it.dri, it.sourceSets)) }) + mapper.writeValueAsString( + nodes.withDescendants().map { NavigationNodeView.from(it, resolver(it.dri, it.sourceSets)) }) }) return input.modified( @@ -88,27 +89,53 @@ object NavigationPageInstaller : PageTransformer { }.sortedBy { it.name.toLowerCase() } } -object ResourceInstaller : PageTransformer { - override fun invoke(input: RootPageNode) = input.modified(children = input.children + resourcePages) - - private val resourcePages = listOf("styles", "scripts", "images").map { - RendererSpecificResourcePage(it, emptyList(), RenderingStrategy.Copy("/dokka/$it")) +object ScriptsInstaller : PageTransformer { + override fun invoke(input: RootPageNode): RootPageNode { + return input.modified( + children = input.children + RendererSpecificResourcePage( + "scripts", + emptyList(), + RenderingStrategy.Copy("/dokka/scripts") + ) + ).transformContentPagesTree { + it.modified( + embeddedResources = it.embeddedResources + listOf( + "scripts/navigationLoader.js", + "scripts/platformContentHandler.js", + "scripts/sourceset_dependencies.js", + "scripts/clipboard.js", + ) + ) + } } } -object StyleAndScriptsAppender : PageTransformer { - override fun invoke(input: RootPageNode) = input.transformContentPagesTree { - it.modified( - embeddedResources = it.embeddedResources + listOf( - "styles/style.css", - "scripts/navigationLoader.js", - "scripts/platformContentHandler.js", - "scripts/sourceset_dependencies.js", - "scripts/clipboard.js", - "styles/jetbrains-mono.css" +object StylesInstaller : PageTransformer { + override fun invoke(input: RootPageNode): RootPageNode = + input.modified( + children = input.children + RendererSpecificResourcePage( + "styles", + emptyList(), + RenderingStrategy.Copy("/dokka/styles") + ) + ).transformContentPagesTree { + it.modified( + embeddedResources = it.embeddedResources + listOf( + "styles/style.css", + "styles/jetbrains-mono.css" + ) ) + } +} + +object AssetsInstaller : PageTransformer { + override fun invoke(input: RootPageNode) = input.modified( + children = input.children + RendererSpecificResourcePage( + "images", + emptyList(), + RenderingStrategy.Copy("/dokka/images") ) - } + ) } class SourcesetDependencyAppender(val context: DokkaContext) : PageTransformer { @@ -118,11 +145,13 @@ class SourcesetDependencyAppender(val context: DokkaContext) : PageTransformer { }.toMap() fun createDependenciesJson(): String = "sourceset_dependencies = '{${ - dependenciesMap.entries.joinToString(", ") { - "\"${it.key}\": [${it.value.joinToString(",") { - "\"$it\"" - }}]" - } + dependenciesMap.entries.joinToString(", ") { + "\"${it.key}\": [${ + it.value.joinToString(",") { + "\"$it\"" + } + }]" + } }}'" val deps = RendererSpecificResourcePage( |