Skip to content

Instantly share code, notes, and snippets.

@lowmess
Last active June 2, 2016 00:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lowmess/f8a8eed4c8e5cfd61d9c to your computer and use it in GitHub Desktop.
Save lowmess/f8a8eed4c8e5cfd61d9c to your computer and use it in GitHub Desktop.
Default Metalsmith build
node_modules
_build
var Metalsmith = require('metalsmith')
var sitemap = require('metalsmith-mapsite')
var feed = require('metalsmith-feed')
var defaultValues = require('metalsmith-default-values')
// HTML
var layouts = require('metalsmith-layouts')
var drafts = require('metalsmith-drafts')
var snippet = require('metalsmith-snippet')
var markdown = require('metalsmith-markdown')
var permalinks = require('metalsmith-permalinks')
var collections = require('metalsmith-collections')
var pagination = require('metalsmith-pagination')
var tags = require('metalsmith-tags')
// CSS
var sass = require('metalsmith-sass')
var prefix = require('metalsmith-autoprefixer')
// JS
var uglify = require('metalsmith-uglify')
// IMAGES
var imagemin = require('metalsmith-imagemin')
var siteBuild = Metalsmith(__dirname)
.source('source')
.destination('_build')
.metadata({
site: {
title: 'My Metalsmith Site',
url: 'http://example.com',
description: 'A website, built with Metalsmith',
keywords: 'metalsmith, blog, static site generator'
}
})
// CSS
.use(sass({
includePaths: require('node-neat').includePaths,
outputStyle: 'compressed',
outputDir: 'css/'
}))
.use(prefix())
// JS
.use(uglify({
concat: 'js/main.js',
removeOriginal: true
}))
// IMAGES
.use(imagemin())
// HTML
.use(drafts())
.use(collections({
blog: {
pattern: 'blog/**/*.md',
sortBy: 'date',
reverse: true
},
pages: {
pattern: '*.md'
}
}))
// Set default values
.use(defaultValues([
{
pattern: 'blog/**/*.md',
defaults: {
layout: 'post.jade'
}
}
]))
.use(pagination({
'collections.blog': {
perPage: 10,
layout: 'blog.jade',
first: 'blog/index.html',
noPageOne: true,
path: 'blog/page/:num/index.html',
pageMetadata: {
title: 'Blog'
}
}
}))
.use(markdown({
gfm: true,
smartypants: true,
tables: true
}))
.use(snippet({
maxLength: 140
}))
.use(permalinks({
pattern: ':collection/:title',
relative: false,
linksets: [{
match: { collection: 'pages' },
pattern: ':title'
}]
}))
.use(tags({
handle: 'tags',
path:'tagged/:tag/index.html',
pathPage: "tagged/:tag/:num/index.html",
perPage: 10,
layout: 'tag.jade',
sortBy: 'date',
reverse: true
}))
.use(layouts({
engine: 'jade',
moment: require('moment'),
directory: 'templates',
default: 'default.jade',
pattern: '**/*.html'
}))
.use(sitemap('http://example.com'))
.use(feed({collection: 'blog'}))
siteBuild.build(function (err) {
if (err) {
console.log(err)
} else {
console.log('Site build complete!')
}
})
{
"name": "my-metalsmith-site",
"version": "0.0.1",
"description": "A website, built with Metalsmith",
"engines": {
"node": "5.0.0"
},
"main": "build.js",
"repository": {
"type": "git",
"url": "git+https://github.com/me/my-metalsmith-site.git"
},
"keywords": [
"metalsmith",
"blog"
],
"author": "Me",
"license": "MIT",
"bugs": {
"url": "https://github.com/me/my-metalsmith-site/issues"
},
"homepage": "https://github.com/me/my-metalsmith-site#readme",
"devDependencies": {
"browser-sync": "^2.12.8",
"jade": "^1.11.0",
"metalsmith": "^2.1.0",
"metalsmith-autoprefixer": "^1.1.0",
"metalsmith-collections": "^0.7.0",
"metalsmith-default-values": "0.0.2",
"metalsmith-drafts": "0.0.1",
"metalsmith-feed": "^0.2.0",
"metalsmith-layouts": "^1.4.2",
"metalsmith-mapsite": "^1.0.4",
"metalsmith-markdown": "^0.2.1",
"metalsmith-pagination": "^1.4.0",
"metalsmith-permalinks": "^0.4.0",
"metalsmith-sass": "^1.3.0",
"metalsmith-snippet": "^2.0.0",
"metalsmith-tags": "^1.2.0",
"metalsmith-uglify": "^1.2.1",
"moment": "^2.11.1",
"node-neat": "^1.7.2",
"nodemon": "^1.9.2"
},
"scripts": {
"start": "node build.js",
"browser_sync": "browser-sync start --server _build --no-ui --no-notify",
"develop": "npm run browser_sync & NODE_ENV=development nodemon --exec 'npm start && browser-sync reload'"
}
}
@lowmess
Copy link
Author

lowmess commented Mar 1, 2016

My default Metalsmith build.

  1. Copy .gitignore, package.json & build.js to root of project
  2. Update contents of package.json & build.js to match your project
  3. npm start now builds your project to the _build directory
  4. npm run develop will watch files for changes and serve files to localhost:3000

Typical file tree structure:

|- source/
    |- blog/
        |- 2016-03-01_blog-post.md
        |- 2016-04-01_another-blog-post.md
    |- stylesheets/
        |- main.scss
    |- scripts/
        |- main.js
    |- 404.md
    |- about.md
    |- contact.md
    |- index.md
|- templates/
    |- partials/
        |- _footer.jade
        |- _head.jade
        |- _navigation.jade
    |- default.jade
|- build.js
|- package.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment