From 80550ae54056b40b2b1ed49270df79710c6c33cf 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 + .../kotlin/versioning/VersioningPlugin.kt | 6 + .../versioning/VersionsNavigationCreator.kt | 12 +- .../kotlin/versioning/htmlPreprocessors.kt | 12 ++ .../resources/dokka/not-found-version.html | 190 ++++++++++++++++++ 5 files changed, 217 insertions(+), 5 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 e9dff82a476..ad1c8267437 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/src/main/kotlin/versioning/VersioningPlugin.kt b/plugins/versioning/src/main/kotlin/versioning/VersioningPlugin.kt index f2c4be2b626..22319099cdc 100644 --- a/plugins/versioning/src/main/kotlin/versioning/VersioningPlugin.kt +++ b/plugins/versioning/src/main/kotlin/versioning/VersioningPlugin.kt @@ -33,6 +33,12 @@ class VersioningPlugin : DokkaPlugin() { before(dokkaBase.baseSearchbarDataInstaller) } } + val notFoundPageInstaller by extending { + dokkaBase.htmlPreprocessors providing ::NotFoundPageInstaller order { + after(dokkaBase.assetsInstaller) + before(dokkaBase.baseSearchbarDataInstaller) + } 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 7ee0dd18f28..876b3ccfabc 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 4c78a9b92af..94400898aff 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 00000000000..abce73dc23d --- /dev/null +++ b/plugins/versioning/src/main/resources/dokka/not-found-version.html @@ -0,0 +1,190 @@ + + + + + Unavailable page + + + + + + + + + + + NOT + FOUND + + + + + + + + + + + + + + + + + +
+
+
+ +
+
+

uh-oh!

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