Search code examples
androidkotlindocumentation-generationkotlin-dokka

How to customize the auto generated Dokka html to include a header and a footer


I'm looking for a way to customize the html generated by Dokka to include a custom header and a footer. I've previously used Doclava in order to override the template for the generated HTML and was wondering if there was a way to do this in Dokka. Looking through their code, I came across the appendHeader and appendFooter functions but wasn't sure on how I can override these methods. https://github.com/Kotlin/dokka/blob/de2f32d91fb6f564826ddd7644940452356e2080/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt#L10

My last resort is to modify the generated html files with a script by inserting a header after the first body tag and inserting the footer before the closing tag but hopefully there's a more elegant solution.

Any help would be greatly appreciated. Thanks!

Edit: Ended up creating a hacky bash script

head=`cat head.html`
header=`cat header.html`
footer=`cat footer.html`

find build/dokka -name "*.html" -type f -exec sed -i "s|</HEAD>|$head</HEAD>|g" {} \;
find .build/dokka -name "*.html" -type f -exec sed -i "s|<BODY>|<BODY>$header|g" {} \;
find build/dokka -name "*.html" -type f -exec sed -i "s|</BODY>|$footer</BODY>|g" {} \;

Solution

  • That's currently impossible I'm afraid. At least it's not straightforward. You can override content generation in StructuredFormatService and then recompile dokka.

    In dokka v0.11.0 we added support for plugins (and rewritten dokka from scratch) and this functionality is one of planned plugins