@@ -16,6 +16,7 @@ const markdown = require('metalsmith-markdown')
16
16
const prism = require ( 'metalsmith-prism' )
17
17
const permalinks = require ( 'metalsmith-permalinks' )
18
18
const pagination = require ( 'metalsmith-yearly-pagination' )
19
+ const htmlMinifier = require ( 'metalsmith-html-minifier' )
19
20
const defaultsDeep = require ( 'lodash.defaultsdeep' )
20
21
const autoprefixer = require ( 'autoprefixer' )
21
22
const marked = require ( 'marked' )
@@ -46,6 +47,33 @@ const markedOptions = {
46
47
renderer
47
48
}
48
49
50
+ const htmlMinifierOpts = {
51
+ collapseBooleanAttributes : true ,
52
+ collapseWhitespace : true ,
53
+ conservativeCollapse : true , // This is needed as things are now
54
+ decodeEntities : true ,
55
+ minifyCSS : {
56
+ level : {
57
+ 1 : {
58
+ specialComments : 0
59
+ }
60
+ }
61
+ } ,
62
+ minifyJS : false , // we don't have a lot inline JS and this slows down things
63
+ minifyURLs : false ,
64
+ processConditionalComments : true ,
65
+ removeAttributeQuotes : true ,
66
+ removeComments : true ,
67
+ removeOptionalAttributes : true ,
68
+ removeOptionalTags : true ,
69
+ removeRedundantAttributes : true ,
70
+ removeScriptTypeAttributes : true ,
71
+ removeStyleLinkTypeAttributes : true ,
72
+ removeTagWhitespace : false ,
73
+ sortAttributes : true ,
74
+ sortClassName : true
75
+ }
76
+
49
77
// This function imports a given language file and uses the default language set
50
78
// in DEFAULT_LANG as a fallback to prevent any strings that aren't filled out
51
79
// from appearing as blank.
@@ -179,6 +207,8 @@ function buildLocale (source, locale, opts) {
179
207
pattern : / \. j s $ /
180
208
} ) )
181
209
. use ( layouts ( ) )
210
+ // Use the default options
211
+ . use ( process . env . NODE_ENV !== 'development' ? htmlMinifier ( { minifierOptions : htmlMinifierOpts } ) : '' )
182
212
// Pipes the generated files into their respective subdirectory in the build
183
213
// directory.
184
214
. destination ( path . join ( __dirname , 'build' , locale ) )
0 commit comments