diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-02-05 15:52:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 15:52:05 +0100 |
commit | a78e47a8d3d0dae7b68b0e414967e20ffb6e9a18 (patch) | |
tree | 12bb2bd7659e7ad3ab6fc8cc62acb0a21524d00c /plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt | |
parent | 70000c87a37caa2a6b518a555f53c98514434403 (diff) | |
download | dokka-a78e47a8d3d0dae7b68b0e414967e20ffb6e9a18.tar.gz dokka-a78e47a8d3d0dae7b68b0e414967e20ffb6e9a18.tar.bz2 dokka-a78e47a8d3d0dae7b68b0e414967e20ffb6e9a18.zip |
Deduplicate resources in multimodule (#1711)
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt')
-rw-r--r-- | plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 6eb68280..2a0af90c 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -731,7 +731,8 @@ open class HtmlRenderer( } } - private fun resolveLink(link: String, page: PageNode): String = if (URI(link).isAbsolute) link else page.root(link) + private val String.isAbsolute: Boolean + get() = URI(this).isAbsolute open fun buildHtml(page: PageNode, resources: List<String>, content: FlowContent.() -> Unit): String { val pathToRoot = locationProvider.pathToRoot(page) @@ -739,23 +740,43 @@ open class HtmlRenderer( head { meta(name = "viewport", content = "width=device-width, initial-scale=1", charset = "UTF-8") title(page.name) - link(href = page.root("images/logo-icon.svg"), rel = "icon", type = "image/svg") + templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) { + link(href = page.root("###images/logo-icon.svg"), rel = "icon", type = "image/svg") + } templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) { script { unsafe { +"""var pathToRoot = "###";""" } } } resources.forEach { when { - it.substringBefore('?').substringAfterLast('.') == "css" -> link( - rel = LinkRel.stylesheet, - href = resolveLink(it, page) - ) - it.substringBefore('?').substringAfterLast('.') == "js" -> script( - type = ScriptType.textJavaScript, - src = resolveLink(it, page) - ) { - async = true + it.substringBefore('?').substringAfterLast('.') == "css" -> + if (it.isAbsolute) link( + rel = LinkRel.stylesheet, + href = it + ) + else templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) { + link( + rel = LinkRel.stylesheet, + href = "###$it" + ) + } + it.substringBefore('?').substringAfterLast('.') == "js" -> + if (it.isAbsolute) script( + type = ScriptType.textJavaScript, + src = it + ) { + async = true + } else templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) { + script( + type = ScriptType.textJavaScript, + src = "###$it" + ) { + async = true + } + } + it.isImage() -> if (it.isAbsolute) link(href = it) + else templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) { + link(href = "###$it") } - it.isImage() -> link(href = page.root(it)) else -> unsafe { +it } } } @@ -779,7 +800,9 @@ open class HtmlRenderer( id = "leftToggler" span("icon-toggler") } - script(type = ScriptType.textJavaScript, src = page.root("scripts/main.js")) {} + templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) { + script(type = ScriptType.textJavaScript, src = "###scripts/main.js") {} + } content() div(classes = "footer") { span("go-to-top-icon") { |