-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path.eleventy.js
65 lines (59 loc) · 1.67 KB
/
.eleventy.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
const htmlmin = require('html-minifier')
const markdownIt = require('markdown-it')
const simpleSvgPlaceholder = require('@cloudfour/simple-svg-placeholder')
const prettier = require('prettier')
// Check for `production` flag
const PRODUCTION = process.env.NODE_ENV === 'production'
// Load settings from `config.js` file
const { PATHS } = require('./config.js')
module.exports = (eleventyConfig) => {
// Markdown Parsing
eleventyConfig.setLibrary(
'md',
markdownIt({
html: true,
breaks: true,
typographer: true
})
)
// Minify HTML Output when `production` flag is set
if (PRODUCTION) {
eleventyConfig.addTransform('htmlmin', (content, outputPath) => {
if (outputPath.endsWith('.html')) {
return htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
})
}
return content
})
} else {
// Prettier HTML Output
eleventyConfig.addTransform('prettier', (content, outputPath) => {
if (outputPath.endsWith('.html')) {
return prettier.format(content, { parser: 'html' })
}
return content
})
}
// Universal filter for placeholder image
const placeholderImageDefaults = {
bgColor: '#f5f5f5',
textColor: '#073983'
}
eleventyConfig.addFilter('placeholderImage', function (value) {
const options = value || {}
return simpleSvgPlaceholder({ ...placeholderImageDefaults, ...options })
})
return {
dir: {
input: 'src',
output: PATHS.dist
},
dataTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
passthroughFileCopy: true
}
}