diff options
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers')
-rw-r--r-- | plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt | 49 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt | 21 |
2 files changed, 47 insertions, 23 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") { diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt index 25d95a8f..c5a92009 100644 --- a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt +++ b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt @@ -104,7 +104,7 @@ class CustomResourceInstaller(val dokkaContext: DokkaContext) : PageTransformer } } -object ScriptsInstaller : PageTransformer { +class ScriptsInstaller(private val dokkaContext: DokkaContext) : PageTransformer { private val scriptsPages = listOf( "scripts/clipboard.js", "scripts/navigation-loader.js", @@ -112,18 +112,18 @@ object ScriptsInstaller : PageTransformer { "scripts/main.js", ) - override fun invoke(input: RootPageNode): RootPageNode { - return input.modified( - children = input.children + scriptsPages.toRenderSpecificResourcePage() - ).transformContentPagesTree { + override fun invoke(input: RootPageNode): RootPageNode = + input.let { root -> + if (dokkaContext.configuration.delayTemplateSubstitution) root + else root.modified(children = input.children + scriptsPages.toRenderSpecificResourcePage()) + }.transformContentPagesTree { it.modified( embeddedResources = it.embeddedResources + scriptsPages ) } - } } -object StylesInstaller : PageTransformer { +class StylesInstaller(private val dokkaContext: DokkaContext) : PageTransformer { private val stylesPages = listOf( "styles/style.css", "styles/logo-styles.css", @@ -132,9 +132,10 @@ object StylesInstaller : PageTransformer { ) override fun invoke(input: RootPageNode): RootPageNode = - input.modified( - children = input.children + stylesPages.toRenderSpecificResourcePage() - ).transformContentPagesTree { + input.let { root -> + if (dokkaContext.configuration.delayTemplateSubstitution) root + else root.modified(children = input.children + stylesPages.toRenderSpecificResourcePage()) + }.transformContentPagesTree { it.modified( embeddedResources = it.embeddedResources + stylesPages ) |