Last active
July 7, 2016 15:52
-
-
Save luisalima/d2b1d58214c63aaec72636a2ccd2ee48 to your computer and use it in GitHub Desktop.
Metalsmith step-by-step
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use `log` from handlebars v3 onwards: | |
http://stackoverflow.com/a/32218903 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* pre-setup for this file: | |
npm init | |
npm install metalsmith --save-dev | |
edit index.js and add the code below: | |
*/ | |
var Metalsmith = require('metalsmith'); | |
Metalsmith(__dirname) // src by default | |
.destination('./build') | |
.build(function(err) { | |
if(err) throw err; | |
console.log('Build finished'); | |
}) | |
/* test: | |
Edit src/index.md and add: | |
## Hello, world! | |
Testing 1 2 3 | |
Run | |
node index.js | |
Output: | |
You should see index.md, as is, inside build/ | |
*/ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Now we are going to transform our markdown into html | |
Pre-setup: | |
npm install metalsmith-markdown --save-dev | |
*/ | |
/* pre-setup for this file: | |
npm init | |
npm install metalsmith --save-dev | |
edit index.js and add the code below: | |
*/ | |
var Metalsmith = require('metalsmith'); | |
Metalsmith(__dirname) // src by default | |
.destination('./build') | |
.use(markdown()) | |
.build(function(err) { | |
if(err) throw err; | |
console.log('Build finished'); | |
}) | |
/* test: | |
Edit src/index.md and add: | |
## Hello, world! | |
Testing 1 2 3 | |
Run | |
node index.js | |
Output: | |
You should see index.html, correctly parsed, inside build/ | |
*/ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Metalsmith(__dirname) | |
.destination('./build') | |
.use(markdown()) | |
.use(layouts({ | |
engine: 'handlebars', | |
directory: 'layouts' | |
})) | |
.build(function(err) { | |
if(err) throw err; | |
console.log('Build finished'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myLogger(files, metalsmith, done) { | |
console.log('Files: '); | |
console.log(files); | |
console.log('\nMetalsmith: '); | |
console.log(metalsmith); | |
done(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment