kt Md Template
fun ktMdTemplate(source: Path, contentKey: String = "content", context: Map<String, Any?> = emptyMap(), includes: List<Path> = emptyList()): (html: String) -> String
Template the source like ktHtml, but it returns a function you can then call with a string to be used as a template. For example, you could do
<html>
<p>
<? content ?>
</p>
</html>Content copied to clipboard
val template = ktHtmlTemplate(src("template.html"))Content copied to clipboard
content will be replaced with the string you call template with:
template("really good content")Content copied to clipboard
You can use this to implement a Markdown template in conjunction with OutputPath.markdownTemplate:
root {
// ...
markdownTemplate = {
val meta = frontmatter["meta"]?.asMap()
val title: String? = meta?.get("title") as? String
val description: String? = meta?.get("description") as? String
val type: String? = meta?.get("type") as? String
ktHtmlTemplate(
src("markdown-template.html"),
context = mapOf("title" to title, "description" to description, "type" to type),
)(it)
}
// ...
}Content copied to clipboard
See also
fun OutputPath.ktMdTemplate(source: Path, contentKey: String = "content", context: Map<String, Any?> = emptyMap()): (html: String) -> String