From 24d41b3388f285437f0bcee940bdf7283844064f Mon Sep 17 00:00:00 2001 From: vmishenev Date: Fri, 17 Sep 2021 16:23:12 +0300 Subject: [PATCH] Add not found page --- .../docs/user_guide/versioning/versioning.md | 2 + plugins/versioning/api/versioning.api | 6 + .../kotlin/versioning/VersioningPlugin.kt | 8 +- .../versioning/VersionsNavigationCreator.kt | 12 +- .../kotlin/versioning/htmlPreprocessors.kt | 12 ++ .../resources/dokka/not-found-version.html | 189 ++++++++++++++++++ 6 files changed, 223 insertions(+), 6 deletions(-) create mode 100644 plugins/versioning/src/main/resources/dokka/not-found-version.html diff --git a/docs/src/doc/docs/user_guide/versioning/versioning.md b/docs/src/doc/docs/user_guide/versioning/versioning.md index e9dff82a47..ad1c826743 100644 --- a/docs/src/doc/docs/user_guide/versioning/versioning.md +++ b/docs/src/doc/docs/user_guide/versioning/versioning.md @@ -14,6 +14,8 @@ Versioning can be configured using: By default, Dokka will try to use semantic versioning to create such ordering. * renderVersionsNavigationOnAllPages - a bool value. By default, Dokka renders a versions navigation on all pages. + +!!! note You should enable the plugin in all submodules to render a versions navigation on all pages. Above configuration should be placed under the `pluginsConfiguration` block specific for your build tool. diff --git a/plugins/versioning/api/versioning.api b/plugins/versioning/api/versioning.api index a339491a3d..15ebe7bea7 100644 --- a/plugins/versioning/api/versioning.api +++ b/plugins/versioning/api/versioning.api @@ -41,6 +41,11 @@ public final class org/jetbrains/dokka/versioning/MultiModuleStylesInstaller : o public fun invoke (Lorg/jetbrains/dokka/pages/RootPageNode;)Lorg/jetbrains/dokka/pages/RootPageNode; } +public final class org/jetbrains/dokka/versioning/NotFoundPageInstaller : org/jetbrains/dokka/transformers/pages/PageTransformer { + public fun (Lorg/jetbrains/dokka/plugability/DokkaContext;)V + public fun invoke (Lorg/jetbrains/dokka/pages/RootPageNode;)Lorg/jetbrains/dokka/pages/RootPageNode; +} + public final class org/jetbrains/dokka/versioning/ReplaceVersionCommandConsumer : org/jetbrains/dokka/base/templating/ImmediateHtmlCommandConsumer { public fun (Lorg/jetbrains/dokka/plugability/DokkaContext;)V public fun canProcess (Lorg/jetbrains/dokka/base/templating/Command;)Z @@ -116,6 +121,7 @@ public final class org/jetbrains/dokka/versioning/VersioningPlugin : org/jetbrai public final fun getCssStyleInstaller ()Lorg/jetbrains/dokka/plugability/Extension; public final fun getDefaultVersioningNavigationCreator ()Lorg/jetbrains/dokka/plugability/Extension; public final fun getDefaultVersioningStorage ()Lorg/jetbrains/dokka/plugability/Extension; + public final fun getNotFoundPageInstaller ()Lorg/jetbrains/dokka/plugability/Extension; public final fun getPreviousDocumentationCopyPostAction ()Lorg/jetbrains/dokka/plugability/Extension; public final fun getReplaceVersionCommandHandler ()Lorg/jetbrains/dokka/plugability/Extension; public final fun getResolveLinkConsumer ()Lorg/jetbrains/dokka/plugability/Extension; diff --git a/plugins/versioning/src/main/kotlin/versioning/VersioningPlugin.kt b/plugins/versioning/src/main/kotlin/versioning/VersioningPlugin.kt index f2c4be2b62..e4e8bbae63 100644 --- a/plugins/versioning/src/main/kotlin/versioning/VersioningPlugin.kt +++ b/plugins/versioning/src/main/kotlin/versioning/VersioningPlugin.kt @@ -30,9 +30,15 @@ class VersioningPlugin : DokkaPlugin() { val cssStyleInstaller by extending { dokkaBase.htmlPreprocessors providing ::MultiModuleStylesInstaller order { after(dokkaBase.assetsInstaller) - before(dokkaBase.baseSearchbarDataInstaller) + before(dokkaBase.customResourceInstaller) } } + val notFoundPageInstaller by extending { + dokkaBase.htmlPreprocessors providing ::NotFoundPageInstaller order { + after(dokkaBase.assetsInstaller) + before(dokkaBase.customResourceInstaller) + } applyIf { !delayTemplateSubstitution } + } val versionsDefaultOrdering by extending { versionsOrdering providing { ctx -> configuration(ctx)?.versionsOrdering?.let { diff --git a/plugins/versioning/src/main/kotlin/versioning/VersionsNavigationCreator.kt b/plugins/versioning/src/main/kotlin/versioning/VersionsNavigationCreator.kt index 7ee0dd18f2..876b3ccfab 100644 --- a/plugins/versioning/src/main/kotlin/versioning/VersionsNavigationCreator.kt +++ b/plugins/versioning/src/main/kotlin/versioning/VersionsNavigationCreator.kt @@ -8,6 +8,7 @@ import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.configuration import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.querySingle +import org.jetbrains.dokka.utilities.urlEncoded import java.io.File interface VersionsNavigationCreator { @@ -62,13 +63,14 @@ class HtmlVersionsNavigationCreator(private val context: DokkaContext) : Version ?.exists() == true val absolutePath = - if(isExistsFile) path?.resolve(relativePosition) else path?.resolve("index.html") - - a(href = absolutePath?.toRelativeString(position)) { if (isExistsFile) - text(version) + path?.resolve(relativePosition) else - strike { text(version) } + versioningStorage.currentVersion.dir.resolve("not-found-version.html") + + a(href = absolutePath?.toRelativeString(position) + + if (!isExistsFile) "?v=" + version.urlEncoded() else "") { + text(version) } } } diff --git a/plugins/versioning/src/main/kotlin/versioning/htmlPreprocessors.kt b/plugins/versioning/src/main/kotlin/versioning/htmlPreprocessors.kt index 4c78a9b92a..94400898af 100644 --- a/plugins/versioning/src/main/kotlin/versioning/htmlPreprocessors.kt +++ b/plugins/versioning/src/main/kotlin/versioning/htmlPreprocessors.kt @@ -22,5 +22,17 @@ class MultiModuleStylesInstaller(private val dokkaContext: DokkaContext) : PageT } } +class NotFoundPageInstaller(private val dokkaContext: DokkaContext) : PageTransformer { + private val notFoundPage = listOf( + "not-found-version.html", + ) + + override fun invoke(input: RootPageNode): RootPageNode = + input.let { root -> + if (dokkaContext.configuration.delayTemplateSubstitution) root + else root.modified(children = input.children + notFoundPage.toRenderSpecificResourcePage()) + } +} + private fun List.toRenderSpecificResourcePage(): List = map { RendererSpecificResourcePage(it, emptyList(), RenderingStrategy.Copy("/dokka/$it")) } diff --git a/plugins/versioning/src/main/resources/dokka/not-found-version.html b/plugins/versioning/src/main/resources/dokka/not-found-version.html new file mode 100644 index 0000000000..259a489312 --- /dev/null +++ b/plugins/versioning/src/main/resources/dokka/not-found-version.html @@ -0,0 +1,189 @@ + + + + + Unavailable page + + + + + + + + + + + NOT + FOUND + + + + + + + + + + + + + + + + + +
+
+
+ +
+
+

uh-oh!

+
You are requesting a page that not + available in documentation version +
+
+
+
+ + \ No newline at end of file