forked from gooodhub/goood-site-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
106 lines (94 loc) · 2.23 KB
/
index.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const metalsmith = require('metalsmith');
const layouts = require('metalsmith-layouts');
const markdown = require('metalsmith-markdown');
const sass = require('metalsmith-sass');
const autoprefixer = require('metalsmith-autoprefixer');
const permalinks = require('metalsmith-permalinks');
const collections = require('metalsmith-collections');
const metalSmithRegisterHelpers = require('metalsmith-register-helpers');
const rootPath = require('metalsmith-rootpath');
const webpackPlugin = require('metalsmith-webpack');
const browserSync = require('./plugins/metalsmith-browser-sync');
const webpackConfig = require('./webpack.conf.js');
const __DEV__ = (process.env.NODE_ENV !== 'production');
const sassParams = () => {
if (__DEV__) {
return {
outputStyle: 'expanded',
sourceMapEmbed: true,
sourcemapContents: true,
};
}
return {
outputStyle: 'compressed',
sourceMap: false,
};
};
const buildApp = metalsmith(__dirname)
.destination('./dist')
.use(rootPath())
// HTML
.use(metalSmithRegisterHelpers({
directory: './layouts/helpers',
}))
.use(collections({
pages: {
pattern: 'pages/*.md',
},
portraits: {
pattern: 'portraits/*.md',
},
ref_ops: {
pattern: 'clients/operations/*.md',
},
ref_org: {
pattern: 'clients/organisation/*.md',
},
ref_offre: {
pattern: 'clients/offre/*.md',
},
}))
.use(markdown())
.use(layouts({
engine: 'handlebars',
partials: 'layouts/partials',
}))
// CSS
.use(sass(sassParams()))
.use(autoprefixer())
// JS - app.js to bundle.js using babel transpiler
.use(webpackPlugin(webpackConfig))
// Routing
.use(permalinks({
pattern: ':slug',
relative: false,
linksets: [
{
match: { collection: 'subPages' },
pattern: ':parent/:slug',
date: 'mmddyy',
},
{
match: { collection: 'pages' },
pattern: ':slug',
},
],
}))
;
// Live reload
if (__DEV__) {
buildApp.use(browserSync({
server: 'dist',
files: [
'layouts/**/*.html',
'src/**/*.scss',
'src/**/*.svg',
'src/**/*.js',
'src/**/*.jpg',
],
port: 55555,
}));
}
buildApp.build((err) => {
if (err) throw err;
});