diff options
Diffstat (limited to 'plugins/base')
13 files changed, 106 insertions, 79 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index be3c09b9..e709b48b 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -198,10 +198,6 @@ class DokkaBase : DokkaPlugin() { htmlPreprocessors with NavigationPageInstaller order { after(rootCreator) } } - val searchPageInstaller by extending { - htmlPreprocessors with SearchPageInstaller order { after(rootCreator) } - } - val scriptsInstaller by extending { htmlPreprocessors with ScriptsInstaller order { after(rootCreator) } } @@ -214,6 +210,14 @@ class DokkaBase : DokkaPlugin() { htmlPreprocessors with AssetsInstaller order { after(rootCreator) } } + val customResourceInstaller by extending { + htmlPreprocessors providing { ctx -> CustomResourceInstaller(ctx) } order { + after(stylesInstaller) + after(scriptsInstaller) + after(assetsInstaller) + } + } + val packageListCreator by extending { htmlPreprocessors providing { PackageListCreator(it, RecognizedLinkFormat.DokkaHtml) diff --git a/plugins/base/src/main/kotlin/DokkaBaseConfiguration.kt b/plugins/base/src/main/kotlin/DokkaBaseConfiguration.kt new file mode 100644 index 00000000..c18b3446 --- /dev/null +++ b/plugins/base/src/main/kotlin/DokkaBaseConfiguration.kt @@ -0,0 +1,14 @@ +package org.jetbrains.dokka.base + +import org.jetbrains.dokka.plugability.ConfigurableBlock +import java.io.File + +data class DokkaBaseConfiguration( + var customStyleSheets: List<File> = defaultCustomStyleSheets, + var customAssets: List<File> = defaultCustomAssets +): ConfigurableBlock { + companion object { + val defaultCustomStyleSheets: List<File> = emptyList() + val defaultCustomAssets: List<File> = emptyList() + } +}
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index 5c0f54d8..f393c0fa 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -15,7 +15,6 @@ import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.renderers.Renderer import org.jetbrains.dokka.transformers.pages.PageTransformer -import java.io.File abstract class DefaultRenderer<T>( protected val context: DokkaContext @@ -223,9 +222,4 @@ abstract class DefaultRenderer<T>( internal typealias SerializedBeforeAndAfter = Pair<String, String> internal typealias InstanceWithSource = Pair<ContentDivergentInstance, DisplaySourceSet> -fun ContentPage.sourceSets() = this.content.sourceSets - -fun ContentEmbeddedResource.isImage(): Boolean { - val imageExtensions = setOf("png", "jpg", "jpeg", "gif", "bmp", "tif", "webp", "svg") - return File(address).extension.toLowerCase() in imageExtensions -} +fun ContentPage.sourceSets() = this.content.sourceSets
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/renderers/FileWriter.kt b/plugins/base/src/main/kotlin/renderers/FileWriter.kt index cd38f1b9..f8c0e882 100644 --- a/plugins/base/src/main/kotlin/renderers/FileWriter.kt +++ b/plugins/base/src/main/kotlin/renderers/FileWriter.kt @@ -33,7 +33,7 @@ class FileWriter(val context: DokkaContext): OutputWriter { } override suspend fun writeResources(pathFrom: String, pathTo: String) = - if (javaClass.getResource(pathFrom).toURI().toString().startsWith(jarUriPrefix)) { + if (javaClass.getResource(pathFrom)?.toURI()?.toString()?.startsWith(jarUriPrefix) == true) { copyFromJar(pathFrom, pathTo) } else { copyFromDirectory(pathFrom, pathTo) @@ -42,9 +42,10 @@ class FileWriter(val context: DokkaContext): OutputWriter { private suspend fun copyFromDirectory(pathFrom: String, pathTo: String) { val dest = Paths.get(root.path, pathTo).toFile() - val uri = javaClass.getResource(pathFrom).toURI() + val uri = javaClass.getResource(pathFrom)?.toURI() + val file = uri?.let { File(it) } ?: File(pathFrom) withContext(Dispatchers.IO) { - File(uri).copyRecursively(dest, true) + file.copyRecursively(dest, true) } } @@ -52,7 +53,11 @@ class FileWriter(val context: DokkaContext): OutputWriter { val rebase = fun(path: String) = "$pathTo/${path.removePrefix(pathFrom)}" val dest = Paths.get(root.path, pathTo).toFile() - dest.mkdirsOrFail() + if(dest.isDirectory){ + dest.mkdirsOrFail() + } else { + dest.parentFile.mkdirsOrFail() + } val uri = javaClass.getResource(pathFrom).toURI() val fs = getFileSystemForURI(uri) val path = fs.getPath(pathFrom) diff --git a/plugins/base/src/main/kotlin/renderers/contentTypeChecking.kt b/plugins/base/src/main/kotlin/renderers/contentTypeChecking.kt new file mode 100644 index 00000000..4619bc53 --- /dev/null +++ b/plugins/base/src/main/kotlin/renderers/contentTypeChecking.kt @@ -0,0 +1,16 @@ +package org.jetbrains.dokka.base.renderers + +import org.jetbrains.dokka.base.renderers.HtmlFileExtensions.imageExtensions +import org.jetbrains.dokka.pages.ContentEmbeddedResource +import java.io.File + +fun ContentEmbeddedResource.isImage(): Boolean { + return File(address).extension.toLowerCase() in imageExtensions +} + +fun String.isImage(): Boolean = + substringBefore('?').substringAfterLast('.') in imageExtensions + +object HtmlFileExtensions { + val imageExtensions = setOf("png", "jpg", "jpeg", "gif", "bmp", "tif", "webp", "svg") +}
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 6bdeae62..7a047d3c 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -679,10 +679,10 @@ open class HtmlRenderer( ) { async = true } + it.isImage() -> link(href = page.root(it)) 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 a5fca92f..a87254ce 100644 --- a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt +++ b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt @@ -7,6 +7,9 @@ import kotlinx.html.h1 import kotlinx.html.id import kotlinx.html.table import kotlinx.html.tbody +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.base.DokkaBaseConfiguration import org.jetbrains.dokka.base.renderers.sourceSets import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.DEnum @@ -14,30 +17,9 @@ import org.jetbrains.dokka.model.DEnumEntry import org.jetbrains.dokka.model.withDescendants import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.configuration import org.jetbrains.dokka.transformers.pages.PageTransformer - -object SearchPageInstaller : PageTransformer { - override fun invoke(input: RootPageNode) = input.modified(children = input.children + searchPage) - - private val searchPage = RendererSpecificResourcePage( - name = "Search", - children = emptyList(), - strategy = RenderingStrategy<HtmlRenderer> { - buildHtml(it, listOf("styles/style.css", "scripts/pages.js", "scripts/search.js")) { - h1 { - id = "searchTitle" - text("Search results for ") - } - table { - tbody { - id = "searchTable" - } - } - } - }) -} - object NavigationPageInstaller : PageTransformer { private val mapper = jacksonObjectMapper() @@ -89,56 +71,79 @@ object NavigationPageInstaller : PageTransformer { }.sortedBy { it.name.toLowerCase() } } +class CustomResourceInstaller(val dokkaContext: DokkaContext) : PageTransformer { + private val configuration = configuration<DokkaBase, DokkaBaseConfiguration>(dokkaContext) + + private val customAssets = configuration?.customAssets?.map { + RendererSpecificResourcePage("images/${it.name}", emptyList(), RenderingStrategy.Copy(it.absolutePath)) + }.orEmpty() + + private val customStylesheets = configuration?.customStyleSheets?.map { + RendererSpecificResourcePage("styles/${it.name}", emptyList(), RenderingStrategy.Copy(it.absolutePath)) + }.orEmpty() + + override fun invoke(input: RootPageNode): RootPageNode { + val customResourcesPaths = (customAssets + customStylesheets).map { it.name }.toSet() + val withEmbeddedResources = input.transformContentPagesTree { it.modified(embeddedResources = it.embeddedResources + customResourcesPaths) } + val (currentResources, otherPages) = withEmbeddedResources.children.partition { it is RendererSpecificResourcePage } + return input.modified(children = otherPages + currentResources.filterNot { it.name in customResourcesPaths } + customAssets + customStylesheets) + } +} + object ScriptsInstaller : PageTransformer { + private val scriptsPages = listOf( + "scripts/clipboard.js", + "scripts/navigation-loader.js", + "scripts/platform-content-handler.js", + "scripts/main.js" + ) + override fun invoke(input: RootPageNode): RootPageNode { return input.modified( - children = input.children + RendererSpecificResourcePage( - "scripts", - emptyList(), - RenderingStrategy.Copy("/dokka/scripts") - ) + children = input.children + scriptsPages.toRenderSpecificResourcePage() ).transformContentPagesTree { it.modified( - embeddedResources = it.embeddedResources + listOf( - "scripts/navigationLoader.js", - "scripts/platformContentHandler.js", - "scripts/sourceset_dependencies.js", - "scripts/clipboard.js", - ) + embeddedResources = it.embeddedResources + scriptsPages ) } } } object StylesInstaller : PageTransformer { + private val stylesPages = listOf( + "styles/style.css", + "styles/logo-styles.css", + "styles/jetbrains-mono.css", + "styles/main.css" + ) + override fun invoke(input: RootPageNode): RootPageNode = input.modified( - children = input.children + RendererSpecificResourcePage( - "styles", - emptyList(), - RenderingStrategy.Copy("/dokka/styles") - ) + children = input.children + stylesPages.toRenderSpecificResourcePage() ).transformContentPagesTree { it.modified( - embeddedResources = it.embeddedResources + listOf( - "styles/style.css", - "styles/jetbrains-mono.css" - ) + embeddedResources = it.embeddedResources + stylesPages ) } } object AssetsInstaller : PageTransformer { + private val imagesPages = listOf( + "images/arrow_down.svg", + "images/docs_logo.svg", + "images/logo-icon.svg" + ) + override fun invoke(input: RootPageNode) = input.modified( - children = input.children + RendererSpecificResourcePage( - "images", - emptyList(), - RenderingStrategy.Copy("/dokka/images") - ) + children = input.children + imagesPages.toRenderSpecificResourcePage() ) } +private fun List<String>.toRenderSpecificResourcePage(): List<RendererSpecificResourcePage> = + map { RendererSpecificResourcePage(it, emptyList(), RenderingStrategy.Copy("/dokka/$it")) } + class SourcesetDependencyAppender(val context: DokkaContext) : PageTransformer { + private val name = "scripts/sourceset_dependencies.js" override fun invoke(input: RootPageNode): RootPageNode { val dependenciesMap = context.configuration.sourceSets.map { it.sourceSetID to it.dependentSourceSets @@ -155,14 +160,14 @@ class SourcesetDependencyAppender(val context: DokkaContext) : PageTransformer { }}'" val deps = RendererSpecificResourcePage( - name = "scripts/sourceset_dependencies.js", + name = name, children = emptyList(), strategy = RenderingStrategy.Write(createDependenciesJson()) ) return input.modified( children = input.children + deps - ) + ).transformContentPagesTree { it.modified(embeddedResources = it.embeddedResources + name) } } } diff --git a/plugins/base/src/main/resources/dokka/images/logo-text.svg b/plugins/base/src/main/resources/dokka/images/logo-text.svg deleted file mode 100755 index 7bf3e6c5..00000000 --- a/plugins/base/src/main/resources/dokka/images/logo-text.svg +++ /dev/null @@ -1,6 +0,0 @@ -<svg width="83" height="27" viewBox="0 0 83 27" fill="none" xmlns="http://www.w3.org/2000/svg"> -<path d="M47.1611 7.6297V25.6345V25.6867H61.8428V21.8039H51.3589V10.3852H61.8428V6.50244H47.1611V7.6297Z" fill="#27282C"/> -<path d="M82.9891 21.8039L72.778 10.3852H82.9051V6.50244H67.0586V10.3852L77.4585 21.8039H67.0586V25.6867H82.9996V21.8039H82.9891Z" fill="#27282C"/> -<path d="M16.2978 7.76556C14.5872 6.46086 12.4463 5.67804 10.1271 5.67804C4.53357 5.67804 0 10.1871 0 15.7503C0 21.3135 4.53357 25.8226 10.1271 25.8226C12.4463 25.8226 14.5872 25.0502 16.2978 23.735V25.7182H20.4955V0H16.2978V7.76556ZM10.1271 21.8041C6.75838 21.8041 4.02984 19.0903 4.02984 15.7399C4.02984 12.3894 6.75838 9.67563 10.1271 9.67563C13.4958 9.67563 16.2243 12.3894 16.2243 15.7399C16.2138 19.0903 13.4853 21.8041 10.1271 21.8041Z" fill="#27282C"/> -<path d="M33.9703 5.86566C28.3768 5.86566 23.8433 10.3747 23.8433 15.9379C23.8433 21.5011 28.3768 26.0102 33.9703 26.0102C39.5638 26.0102 44.0974 21.5011 44.0974 15.9379C44.0974 10.3747 39.5638 5.86566 33.9703 5.86566ZM33.9703 21.9917C30.6016 21.9917 27.8731 19.2779 27.8731 15.9275C27.8731 12.577 30.6016 9.86325 33.9703 9.86325C37.339 9.86325 40.0676 12.577 40.0676 15.9275C40.0676 19.2779 37.339 21.9917 33.9703 21.9917Z" fill="#27282C"/> -</svg> diff --git a/plugins/base/src/main/resources/dokka/scripts/navigationLoader.js b/plugins/base/src/main/resources/dokka/scripts/navigation-loader.js index c2f60ec5..c2f60ec5 100644 --- a/plugins/base/src/main/resources/dokka/scripts/navigationLoader.js +++ b/plugins/base/src/main/resources/dokka/scripts/navigation-loader.js diff --git a/plugins/base/src/main/resources/dokka/scripts/platformContentHandler.js b/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js index 022aca4f..022aca4f 100644 --- a/plugins/base/src/main/resources/dokka/scripts/platformContentHandler.js +++ b/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js diff --git a/plugins/base/src/main/resources/dokka/scripts/search.js b/plugins/base/src/main/resources/dokka/scripts/search.js deleted file mode 100644 index 04d88ab5..00000000 --- a/plugins/base/src/main/resources/dokka/scripts/search.js +++ /dev/null @@ -1,7 +0,0 @@ -let query = new URLSearchParams(window.location.search).get("query"); -document.getElementById("searchTitle").innerHTML += '"' + query + '":'; -document.getElementById("searchTable").innerHTML = pages - .filter(el => el.name.toLowerCase().startsWith(query.toLowerCase())) - .reduce((acc, element) => { - return acc + '<tr><td><a href="' + element.location + '">' + element.name + '</a></td></tr>' - }, "");
\ No newline at end of file diff --git a/plugins/base/src/main/resources/dokka/styles/logo-styles.css b/plugins/base/src/main/resources/dokka/styles/logo-styles.css new file mode 100644 index 00000000..a3a07d75 --- /dev/null +++ b/plugins/base/src/main/resources/dokka/styles/logo-styles.css @@ -0,0 +1,3 @@ +#logo { + background-image: url(../images/docs_logo.svg); +}
\ No newline at end of file diff --git a/plugins/base/src/main/resources/dokka/styles/style.css b/plugins/base/src/main/resources/dokka/styles/style.css index 24fd8fa3..7c1b2803 100644 --- a/plugins/base/src/main/resources/dokka/styles/style.css +++ b/plugins/base/src/main/resources/dokka/styles/style.css @@ -191,7 +191,6 @@ background-size: 125px 26px; border-bottom: 1px solid #DADFE6; background-repeat: no-repeat; - background-image: url(../images/docs_logo.svg); background-origin: content-box; padding-left: 24px; padding-top: 24px; |