-
Notifications
You must be signed in to change notification settings - Fork 2
/
metalsmith.js
86 lines (80 loc) · 2.36 KB
/
metalsmith.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const path = require('path');
const Metalsmith = require('metalsmith');
const drafts = require('metalsmith-drafts');
const layout = require('metalsmith-layouts');
const markdown = require('metalsmith-markdown');
const highlighting = require('metalsmith-metallic');
const permalinks = require('metalsmith-permalinks');
const assets = require('metalsmith-assets');
const branch = require('metalsmith-branch');
const sass = require('metalsmith-sass');
const filter = require('metalsmith-filter');
const collections = require('metalsmith-collections');
const ignore = require('metalsmith-ignore');
const browserSync = require('metalsmith-browser-sync');
const dates = require('metalsmith-date-formatter');
const helpers = require('metalsmith-register-helpers');
const sitemap = require('metalsmith-sitemap');
const youtube = require('metalsmith-youtube');
const redirect = require('metalsmith-redirect');
const config = require('./configs');
module.exports = function (mode) {
const buildTarget = mode === 'deploy' ? './.deploy_git' : './public';
const srcDir = path.join(__dirname, './source');
const buildDir = path.join(__dirname, buildTarget);
const metalsmith = new Metalsmith(__dirname)
.destination(buildDir)
.use(branch('styles/main.scss')
.use(sass({
includePaths: [path.join(__dirname, './source/styles/')],
outputDir: 'styles/',
}))
)
.metadata(config.globals)
.use(ignore([
'styles/*.scss',
'styles/**/*.scss',
'styles/**/.DS_Store', // thx os x :(
]))
.source(srcDir)
.use(drafts())
.use(collections(config.collections))
.use(highlighting())
.use(youtube({
suggested: false,
controls: true,
showTitle: true,
privacy: true,
}))
.use(dates({ format: 'D MMMM, YYYY' }))
.use(markdown())
.use(permalinks(config.permalinks))
.use(helpers({
directory: path.join(__dirname, './views/helpers'),
}))
.use(layout(config.layout))
.use(assets({
source: './assets',
destination: './assets',
}))
.use(sitemap({
hostname: 'https://bengsfort.github.io/',
omitIndex: true,
}))
.use(redirect(config.redirects));
if (mode === 'watch') {
metalsmith.use(browserSync({
files: [
`${srcDir}/**/*`,
`${srcDir}/views/**/*`,
`${srcDir}/configs/**/*`,
`${srcDir}/assets/**/*`,
],
server: buildDir,
}));
}
metalsmith.build(function(err) {
if (err) throw err;
console.log('Build complete!');
});
};