Skip to content

Instantly share code, notes, and snippets.

@sampsyo
Created March 5, 2018 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sampsyo/0fb964a98f8afe66f485add0f5b22785 to your computer and use it in GitHub Desktop.
Save sampsyo/0fb964a98f8afe66f485add0f5b22785 to your computer and use it in GitHub Desktop.
a Metalsmith config
var Metalsmith = require('metalsmith');
var markdown = require('metalsmith-markdown');
var layouts = require('metalsmith-layouts');
var sass = require('metalsmith-sass');
var metadata = require('metalsmith-metadata');
var inplace = require('metalsmith-in-place');
var ignore = require('metalsmith-ignore');
var metadataPat = require('./metalsmith-metadata-pattern');
var marked = require('marked');
var moment = require('moment');
var serveMode = process.argv.indexOf('--serve') != -1;
var site = Metalsmith(__dirname)
.source('./src')
.destination('./build')
.metadata({
serve: serveMode,
prefix: serveMode ? '' : '/private',
})
.use(ignore(['**/.DS_Store']))
.use(sass())
// Scheduling.
.use(metadata({
lunch: 'lunch.yaml',
}))
.use(metadataPat({
schedules: 'schedules/*.yaml',
}))
.use(inplace({
'engineOptions': {
// Filters/globals for Nunjucks.
'filters': {
'markdown': function (str) {
return marked(str, { smartypants: true });
},
'date': function (d, f) {
return moment(d).format(f);
},
'time': function (d, f) {
return moment(d, 'hh:mma').format(f);
},
},
'globals': {
'now': function (f) {
return moment().format(f);
},
},
}
}))
.use(markdown({
smartypants: true,
}))
.use(layouts('nunjucks'));
if (serveMode) {
var serve = require('metalsmith-serve');
var watch = require('metalsmith-watch');
site = site
.use(serve())
.use(watch({
paths: {
"${source}/**/*": true,
"layouts/**/*": "**/*.md",
"${source}/**/*.yaml": "**/*",
},
livereload: true
}));
}
site.build(function(err) {
if (err) throw err;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment