-
Notifications
You must be signed in to change notification settings - Fork 21
/
base.js
133 lines (117 loc) · 3.37 KB
/
base.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
var Metalsmith = require('metalsmith'),
filenames = require("metalsmith-filenames"),
date = require('metalsmith-build-date'),
layouts = require('metalsmith-layouts'),
i18n = require('metalsmith-i18n'),
mapsite = require('metalsmith-mapsite'),
permalinks = require('metalsmith-permalinks'),
ignore = require('metalsmith-ignore'),
rename = require('metalsmith-rename'),
fingerprint = require('metalsmith-fingerprint'),
inPlace = require('metalsmith-in-place'),
imagemin = require('metalsmith-imagemin'),
uglify = require('metalsmith-uglify'),
stylus = require('metalsmith-stylus'),
autoprefixer = require('metalsmith-autoprefixer'),
assets = require('metalsmith-assets');
handlebars = require('handlebars');
handlebars.registerHelper('ifequals', function (item, comparison, options) {
if (item == comparison) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
handlebars.registerHelper('isActive', function (currentPage, pages) {
const pagesArray = pages.split(',');
return pagesArray.includes(currentPage);
});
handlebars.registerHelper({
and: function () {
return Array.prototype.slice.call(arguments, 0, -1).every(Boolean);
},
or: function () {
return Array.prototype.slice.call(arguments, 0, -1).some(Boolean);
}
});
handlebars.registerHelper('join', function() {
const elements = Array.from(arguments)
return elements.slice(0, -1).join('');
})
module.exports = {
getMetalsmith: function (locale) {
var destination = 'build/' + locale;
var metalsmith = new Metalsmith(__dirname)
// Config
.use(filenames)
.use(ignore([
"layouts/*",
"locales/*",
"partials/*",
"styles/mixins/*",
"styles/_*",
]))
.use(date)
// Images
//.use(imagemin({
//optimizationLevel: 3,
//svgoPlugins: [{ removeViewBox: false }]
//}))
//Javascript
.use(uglify({
filter: ['js/vendors/*.js', 'js/*.js'],
removeOriginal: true,
sourceMap: true,
order: ['js/vendors/**/*.js', 'js/*.js'],
concat: 'js/main.min.js'
}))
// Styles
.use(stylus())
.use(autoprefixer({
browsers : ['last 2 versions'],
cascade : false
}))
.use(fingerprint({
pattern: 'styles/main.css'
}))
// Translation
.use(i18n({
default: locale,
locales: ['en', 'fr', 'es'],
directory: 'src/locales'
}))
.use(function locales(files, metalsmith, done) {
for (var file in files) {
files[file].locale = locale;
done();
};
}
)
// Bootstrap
.use(assets({
source: './node_modules/cozy-bootstrap/dist/',
destination: './styles'
}))
// HTML
.use(layouts({
engine: 'handlebars',
directory: 'src/layouts',
partials: "src/partials"
}))
.use(inPlace({
engine: 'handlebars',
directory: 'src'
}))
// Misc
.use(mapsite({
omitExtension: true,
hostname: "https://cozy.io/" + locale
}))
.use(permalinks({
pattern: ':title',
relative: false
}))
.destination(destination);
return metalsmith;
}
}