-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
51 lines (42 loc) · 1.5 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
const eleventyGoogleFonts = require('eleventy-google-fonts')
const Image = require('@11ty/eleventy-img')
module.exports = (eleventyConfig) => {
eleventyConfig.addPlugin(eleventyGoogleFonts)
/*===================================================*/
/* files that need to be copied to the build folder */
/*===================================================*/
eleventyConfig.addPassthroughCopy('./src/assets/images')
eleventyConfig.addPassthroughCopy('./src/assets/icons')
eleventyConfig.addPassthroughCopy('./src/assets/sprite.svg')
eleventyConfig.addPassthroughCopy({
'node_modules/svg-icon-sprite/dist/svg-icon-sprite.js': 'assets/svg-icon-sprite.js'
})
const imageShortcode = async (imageObj = {}) => {
const widths = imageObj.widths || [300, 600, 900, 1200]
const className = imageObj.className || "image"
const sizes = "(min-width: 100px) 50vw, 100vw"
const metadata = await Image(imageObj.src, {
formats: ["webp", "jpeg"],
outputDir: "./public/assets/images/generated/",
urlPath: "/assets/images/generated/",
widths: widths
})
const alt = imageObj.alt;
const imageAttributes = {
class: className,
alt,
sizes,
loading: "lazy",
decoding: "async",
}
return Image.generateHTML(metadata, imageAttributes)
}
eleventyConfig.addAsyncShortcode('image', imageShortcode)
return {
dir: {
input: 'src',
output: 'public',
},
markdownTemplateEngine: 'njk'
}
}