diff options
Diffstat (limited to 'plugins/all-module-page/src/main/kotlin/templates/DirectiveBasedTemplateProcessing.kt')
-rw-r--r-- | plugins/all-module-page/src/main/kotlin/templates/DirectiveBasedTemplateProcessing.kt | 54 |
1 files changed, 7 insertions, 47 deletions
diff --git a/plugins/all-module-page/src/main/kotlin/templates/DirectiveBasedTemplateProcessing.kt b/plugins/all-module-page/src/main/kotlin/templates/DirectiveBasedTemplateProcessing.kt index 92f39779..feba2d4e 100644 --- a/plugins/all-module-page/src/main/kotlin/templates/DirectiveBasedTemplateProcessing.kt +++ b/plugins/all-module-page/src/main/kotlin/templates/DirectiveBasedTemplateProcessing.kt @@ -5,9 +5,6 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.jetbrains.dokka.allModulesPage.AllModulesPagePlugin -import org.jetbrains.dokka.base.DokkaBase -import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation -import org.jetbrains.dokka.base.resolvers.shared.PackageList import org.jetbrains.dokka.base.templating.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.plugin @@ -16,16 +13,16 @@ import org.jsoup.Jsoup import org.jsoup.nodes.* import org.jsoup.parser.Tag import java.io.File -import java.net.URL import java.nio.file.Files import java.util.concurrent.ConcurrentHashMap -class DirectiveBasedTemplateProcessingStrategy(private val context: DokkaContext) : TemplateProcessingStrategy { +class DirectiveBasedHtmlTemplateProcessingStrategy(private val context: DokkaContext) : TemplateProcessingStrategy { private val navigationFragments = ConcurrentHashMap<String, Element>() private val substitutors = context.plugin<AllModulesPagePlugin>().query { substitutor } + private val externalModuleLinkResolver = ExternalModuleLinkResolver(context) - override suspend fun process(input: File, output: File): Unit = coroutineScope { + override suspend fun process(input: File, output: File): Boolean = coroutineScope { if (input.extension == "html") { launch { val document = withContext(IO) { Jsoup.parse(input, "UTF-8") } @@ -40,11 +37,8 @@ class DirectiveBasedTemplateProcessingStrategy(private val context: DokkaContext } withContext(IO) { Files.write(output.toPath(), listOf(document.outerHtml())) } } - } else { - launch(IO) { - Files.copy(input.toPath(), output.toPath()) - } - } + true + } else false } private fun substitute(element: Element, commandContext: TemplatingContext<SubstitutionCommand>) { @@ -118,32 +112,9 @@ class DirectiveBasedTemplateProcessingStrategy(private val context: DokkaContext } private fun resolveLink(it: Element, command: ResolveLinkCommand, fileContext: File) { - val elpFactory = context.plugin<DokkaBase>().query { externalLocationProviderFactory } - - val packageLists = - context.configuration.modules.map { it.sourceOutputDirectory.resolve(it.relativePathToOutputDirectory) } - .map { module -> - module to PackageList.load( - URL("file:" + module.resolve("package-list").path), - 8, - true - ) - }.toMap() - - val externalDocumentations = - packageLists.map { (module, pckgList) -> - ExternalDocumentation( - URL("file:/${module.name}/${module.name}"), - pckgList!! - ) - } - val elps = elpFactory - .flatMap { externalDocumentations.map { ed -> it.getExternalLocationProvider(ed) } } - .filterNotNull() - - val absoluteLink = elps.mapNotNull { it.resolve(command.dri) }.firstOrNull() - if (absoluteLink == null) { + val link = externalModuleLinkResolver.resolve(command.dri, fileContext) + if (link == null) { val children = it.childNodes().toList() val attributes = Attributes().apply { put("data-unresolved-link", command.dri.toString()) @@ -155,17 +126,6 @@ class DirectiveBasedTemplateProcessingStrategy(private val context: DokkaContext return } - val modulePath = context.configuration.outputDir.absolutePath.split(File.separator) - val contextPath = fileContext.absolutePath.split(File.separator) - val commonPathElements = modulePath.zip(contextPath) - .takeWhile { (a, b) -> a == b }.count() - - // -1 here to not drop the last directory - val link = - (List(contextPath.size - commonPathElements - 1) { ".." } + modulePath.drop(commonPathElements)).joinToString( - "/" - ) + absoluteLink.removePrefix("file:") - val attributes = Attributes().apply { put("href", link) // TODO: resolve } |