-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
59 lines (51 loc) · 1.46 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
import Image from '@11ty/eleventy-img'
import fs from 'fs'
export default function (config) {
// Add passthrough copies
config.addPassthroughCopy({ public: './' })
config.addPassthroughCopy({ 'src/robots.txt': '/robots.txt' })
// Add filters
config.addFilter('criticalExists', () => fs.existsSync('./critical.min.css'))
config.addFilter('getCritical', () => fs.readFileSync('./critical.min.css'))
// Image shortcode
async function imageShortcode(src, alt, sizes) {
let metadata = await Image(src, {
widths: [445, null],
formats: ['webp', 'jpg'],
urlPath: '/images/',
outputDir: './dist/images/',
})
return Image.generateHTML(metadata, {
sizes,
alt,
loading: 'lazy',
decoding: 'async',
})
}
config.addNunjucksAsyncShortcode('image', imageShortcode)
// Portfolio image shortcode
async function portfolioImageShortcode(src, alt) {
let metadata = await Image(src, {
widths: [null],
formats: ['webp'],
urlPath: '/images/',
outputDir: './dist/images/',
})
return metadata.webp[metadata.webp.length - 1].url
}
config.addNunjucksAsyncShortcode('portfolioImage', portfolioImageShortcode)
// Set BrowserSync config
config.setBrowserSyncConfig({
files: ['dist/**/*'],
open: true,
})
// Set directory configuration
return {
dir: {
input: 'src',
output: 'dist',
includes: '_includes',
},
markdownTemplateEngine: 'njk',
}
}