Skip to content

Commit

Permalink
Fix resolved page isHtml computation & render html template containin…
Browse files Browse the repository at this point in the history
…g pages as html (not dokka)
  • Loading branch information
mkondratek authored and romanowski committed Sep 3, 2020
1 parent ec54b4e commit 4d0fcd5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
6 changes: 6 additions & 0 deletions documentation/docs/static-page/random.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
layout: vl_header
title: Sample html page
---

Hello world!
6 changes: 4 additions & 2 deletions documentation/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
layout: vl_header
---

# Dokka site

**Generate a static documentation for in your dokka project**



**Yes, this page was generated using dokka-site**

You can learn more from out [documentation](dokka-site/index.html).
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/com/virtuslab/dokka/site/processors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class SiteResourceManager(cxt: DokkaContext) : BaseStaticSiteProcessor(cxt) {
}
}.toSet()


override fun transform(input: RootPageNode): RootPageNode {
val images = File(root, "images").walkTopDown().filter { it.isFile }
.map { root.toPath().relativize(it.toPath()).toString() }
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/virtuslab/dokka/site/renderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class ExternalDocsToolRenderer(context: DokkaContext) : org.jetbrains.dokka.base
is BaseStaticSiteProcessor.MdPageNode ->
if (page.dri.contains(docsRootDRI)) {
val parser: Parser = Parser.builder().build()
val htmlContent =
HtmlRenderer.builder(defaultMarkdownOptions).build().render(parser.parse(page.resolved.code))
val htmlRenderer = HtmlRenderer.builder(defaultMarkdownOptions).build()
val htmlContent = htmlRenderer.render(parser.parse(page.resolved.code))
createHtml(page, htmlContent)
} else super.buildHtml(page, resources, content)
else ->
Expand Down
19 changes: 13 additions & 6 deletions src/main/kotlin/com/virtuslab/dokka/site/templates.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,30 @@ data class TemplateFile(val file: File, val rawCode: String, private val setting
fun title(): String = stringSetting("title") ?: name()
fun layout(): String? = stringSetting("layout")


fun resolve(ctx: RenderingContext): ResolvedPage =
resolveInner(ctx.copy(properties = HashMap(ctx.properties) + ("page" to mapOf("title" to title()))), hasHtmlContent = false)
resolveInner(
ctx = ctx.copy(properties = HashMap(ctx.properties) + ("page" to mapOf("title" to title()))),
hasHtmlContent = false
)

private fun resolveInner(ctx: RenderingContext, hasHtmlContent: Boolean): ResolvedPage {
if (ctx.resolving.contains(file.absolutePath))
throw java.lang.RuntimeException("Cycle in templates involving $file: ${ctx.resolving}")

val rendered = Template.parse(this.rawCode).render(HashMap(ctx.properties)) // Library requires mutable maps..
val code = if (!(isHtml || hasHtmlContent)) rendered else {
val toBeResolvedIsHtml = isHtml || hasHtmlContent
val code = if (!toBeResolvedIsHtml) rendered else {
val parser: Parser = Parser.builder().build()
HtmlRenderer.builder(ctx.markdownOptions).build().render(parser.parse(rendered))
}
val resources = listSetting("extraCSS") + listSetting("extraJS")
return layout()?.let {
val layoutTemplate = ctx.layouts[it] ?: throw RuntimeException("No layouts named $it in ${ctx.layouts}")
layoutTemplate.resolveInner(ctx.nest(code, file.absolutePath, resources), hasHtmlContent = isHtml)
} ?: ResolvedPage(code, isHtml, resources + ctx.resources)
layoutTemplate.resolveInner(
ctx = ctx.nest(code, file.absolutePath, resources),
hasHtmlContent = toBeResolvedIsHtml
)
} ?: ResolvedPage(code, toBeResolvedIsHtml, resources + ctx.resources)
}
}

Expand All @@ -124,5 +130,6 @@ fun loadTemplateFile(file: File): TemplateFile {
return TemplateFile(
file = file,
rawCode = content.joinToString(LineSeparator),
settings = yamlCollector.data)
settings = yamlCollector.data
)
}

0 comments on commit 4d0fcd5

Please sign in to comment.