-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
68 lines (58 loc) · 1.86 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Metalsmith build file
* Build site with `node build`
*/
// Get our requirements, installed by npm
const metalsmith = require('metalsmith'); // Static site generator
const collections = require('metalsmith-collections'); // Group content into collections
const inPlace = require('metalsmith-in-place'); // Render templating syntax in source files
const codeHighlight = require('metalsmith-code-highlight'); // Syntax highlighter
const layouts = require('metalsmith-layouts'); // Apply layouts to source files
const assets = require('metalsmith-static'); // Copy assets into build directory without manipulating
const browserSync = require('metalsmith-browser-sync'); // Local server
const templateConfig = {
directory: 'views',
engineOptions: {
noCache: true, // never use a cache and recompile templates each time
}
}
// Run Metalsmith in the current directory
metalsmith(__dirname)
.clean(true) // Clean the destination directory before build
.source('./src') // Set page source directory
.destination('./html-build') // Set destination directory
// Render templating syntax in source files
.use(inPlace(templateConfig))
// Syntax highlighter
.use(codeHighlight())
// Group content into collections
.use(collections({
components: {
pattern: ['components/**/*', '!components/index.html']
},
templates: {
pattern: ['templates/**/*', '!templates/index.html']
},
styles: {
pattern: ['styles/**/*', '!styles/index.html']
}
}))
// Copy assets into build directory
.use(assets({
src: './assets',
dest: './assets'
}))
// Apply layouts to source files
.use(layouts(templateConfig))
// Local server
.use(browserSync({
server: 'html-build',
files: ['assets/**/*', 'src/**/*', 'views/**/*', 'macros/**/*']
}))
// Tell Metalsmith to build the site
.build(function(error) {
if (error) {
throw error;
}
console.log('Build finished');
});