Skip to content

Instantly share code, notes, and snippets.

@jhyland87
Last active December 1, 2016 15:44
Show Gist options
  • Save jhyland87/4f0a1c04683ac4e8cea84afa6063dc93 to your computer and use it in GitHub Desktop.
Save jhyland87/4f0a1c04683ac4e8cea84afa6063dc93 to your computer and use it in GitHub Desktop.
include() BEFORE & AFTER layouts()
const Metalsmith = require('metalsmith');
const layouts = require( 'metalsmith-layouts' )
const markdown = require('metalsmith-markdown')
const include = require('metalsmith-include')
const config = {
source: 'src',
buildPath: 'public'
}
Metalsmith(__dirname)
.source( config.source )
.destination( config.buildPath )
.clean(true)
.use(markdown({
html: true,
xhtmlOut: true,
typographer: true,
linkify: true
}))
.use(include({
deletePartials: true
}))
.use(layouts({
engine: 'pug',
pretty: true,
directory: 'templates'
}))
.use(include({
engine:'pug',
inPlace: true,
deletePartials: false
}))
.build(function(err, files){
if (err) {
console.log('ERROR:',err)
return
}
console.log( 'Build Completed' )
console.log( 'Files:', Object.keys( files ) )
})
/**
* Resulting content of public/home.html
<!-- Begin: home.pug-->
<div class="main"><h3 id="welcome-to-my-website-">Welcome to my website!</h3>
<h4 id="thanks-for-visiting-">Thanks for visiting!</h4>
</div>
<!-- End: home.pug-->
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment