Antoine Toulme
Antoine Toulme

Reputation: 974

How can I add a footer to Kotlin Dokka docs?

I am looking for a way to include text in the footer of all Dokka generated docs. I am not seeing this option being advertised by the Gradle or Maven plugins for Dokka.

Is this possible? Can you point me to a sample?

Upvotes: 5

Views: 820

Answers (3)

D.A.H
D.A.H

Reputation: 917

If you have Maven project then you can do it by adding plugin into pom.xml

        <plugin>
            <groupId>org.jetbrains.dokka</groupId>
            <artifactId>dokka-maven-plugin</artifactId>
            <version>1.9.20</version>
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>dokka</goal>
                        <goal>javadoc</goal>
                        <goal>javadocJar</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <moduleName>Demo App</moduleName>
                <skipEmptyPackages>true</skipEmptyPackages>
                <includeNonPublic>true</includeNonPublic>
                <includes>
                    <include>module.md</include>
                    <include>src/main/kotlin/org/demo/gear/package.md</include>
                    <include>src/main/kotlin/org/demo/utils/misc/package.md</include>
                    <include>src/main/kotlin/org/demo/app/package.md</include>
                </includes>
                <samples>
                    <dir>src/test</dir>
                    <dir>src/main</dir>
                </samples>
                <pluginsConfiguration>
                    <org.jetbrains.dokka.base.DokkaBase>
                        <footerMessage>
                            <![CDATA[2025 <a href="https://demo.org/">demo.org</a>]]>
                        </footerMessage>
                        <separateInheritedMembers>true</separateInheritedMembers>
                    </org.jetbrains.dokka.base.DokkaBase>
                </pluginsConfiguration>
            </configuration>
        </plugin>

Upvotes: 0

Shazbot
Shazbot

Reputation: 1494

You can set your own footer by overriding the Dokka footer message.

{module}/build.gradle

tasks.named("dokkaHtml").configure {
  pluginsMapConfiguration.set(
    [
      "org.jetbrains.dokka.base.DokkaBase": """{
        "footerMessage": "Your New Footer!"
      }"""
    ]
  )
}

This will replace the Copyright 20xx in the current footer. For further details on multi-module / css support, recommend checking out the source below.

Source: Raywenderlich

Upvotes: 2

Andy Jazz
Andy Jazz

Reputation: 58533

There are two instance methods in dokka package – one for footer, one for header:

fun appendFooter(to:) { }

fun appendHeader(to:, title:, basePath:) { }

Here's a real code how it looks like:

package org.jetbrains.dokka

import java.io.File

interface HtmlTemplateService {

    fun appendHeader(to: StringBuilder, title: String?, basePath: File)
    fun appendFooter(to: StringBuilder)

    companion object {

        fun default(css: String? = null): HtmlTemplateService {
            return object : HtmlTemplateService {

                override fun appendFooter(to: StringBuilder) {
                    if (!to.endsWith('\n')) {
                        to.append('\n')
                    }
                    to.appendln("</BODY>")
                    to.appendln("</HTML>")
                }
                override fun appendHeader(to: StringBuilder, title: String?, basePath: File) {
                    to.appendln("<HTML>")
                    to.appendln("<HEAD>")
                    to.appendln("<meta charset=\"UTF-8\">")
                    if (title != null) {
                        to.appendln("<title>$title</title>")
                    }
                    if (css != null) {
                        val cssPath = basePath.resolve(css)
                        to.appendln("<link rel=\"stylesheet\" href=\"$cssPath\">")
                    }
                    to.appendln("</HEAD>")
                    to.appendln("<BODY>")
                }
            }
        }
    }
} 

I think it must be working even in dokka.playground.

Hope this helps.

Upvotes: 0

Related Questions