A Metalsmith plugin to render files with Marko templates.
It supports rendering source files with templates and layouts. By default it looks for layout files in layouts
directory. You need to set the layout
in source file frontmatter section in order to render it in a layout. Optionally, you can set defaultLayout
in plugin options.
$ npm install metalsmith-marko
let marko = require("metalsmith-marko")
metalsmith.use(marko())
let marko = require("metalsmith-marko")
metalsmith.use(marko({
layoutsDirectory: "layouts",
defaultLayout: "default.html",
pattern: ["**/*.marko", "**/*.html"],
compilerOptions: {
writeToDisk: false,
preserveWhitespace: true
}
}))
layoutsDirectory: "layouts",
pattern: ["**/*.marko"],
compilerOptions: {
writeToDisk: false,
preserveWhitespace: true
}
layouts/default.html.marko
<!DOCTYPE html>
<html>
<head>
<title>${data.title}</title>
</head>
<body>
$!{data.contents}
</body>
</html>
pages/index.html.marko
<article>
<h1>Heading</h1>
<div for(page in data.pages)>${page.title}</div>
</article>