|
1 | 1 | const yaml = require('js-yaml'); |
| 2 | +const { join } = require('path'); |
2 | 3 | const rss = require('@11ty/eleventy-plugin-rss'); |
3 | 4 | const { DateTime } = require('luxon'); |
| 5 | +const Image = require('@11ty/eleventy-img'); |
4 | 6 | const markdown = require('markdown-it')({ |
5 | 7 | html: true, |
6 | 8 | }); |
@@ -30,13 +32,41 @@ const MONTHS = [ |
30 | 32 | 'Dicembre', |
31 | 33 | ]; |
32 | 34 |
|
33 | | -module.exports = function(eleventyConfig) { |
| 35 | +module.exports = function (eleventyConfig) { |
34 | 36 | const assets = ['js', 'css', 'fonts', 'img', 'odx-assets', 'admin']; |
35 | 37 |
|
36 | 38 | for (const folder of assets) { |
37 | 39 | eleventyConfig.addPassthroughCopy({ [`static/${folder}`]: folder }); |
38 | 40 | } |
39 | 41 |
|
| 42 | + eleventyConfig.addNunjucksAsyncShortcode( |
| 43 | + 'image', |
| 44 | + async function ( |
| 45 | + src, |
| 46 | + alt, |
| 47 | + imgClass = 'img-rounded img-responsive center-block', |
| 48 | + ) { |
| 49 | + if (alt === undefined) { |
| 50 | + // You bet we throw an error on missing alt (alt="" works okay) |
| 51 | + throw new Error(`Missing \`alt\` on myImage from: ${src}`); |
| 52 | + } |
| 53 | + |
| 54 | + const image = await Image(join('static', src), { |
| 55 | + widths: [null], |
| 56 | + formats: ['webp', 'jpeg'], |
| 57 | + urlPath: '/img/', |
| 58 | + outputDir: './_site/img/', |
| 59 | + }); |
| 60 | + |
| 61 | + const { url, width, height } = image.jpeg[0]; |
| 62 | + |
| 63 | + return `<picture> |
| 64 | + <source srcset="${image.webp[0].url}" type="image/webp" /> |
| 65 | + <img class="${imgClass}" src="${url}" width="${width}" height="${height}" alt="${alt}" loading="lazy" /> |
| 66 | + </picture>`; |
| 67 | + }, |
| 68 | + ); |
| 69 | + |
40 | 70 | eleventyConfig.addPlugin(rss); |
41 | 71 |
|
42 | 72 | eleventyConfig.addPassthroughCopy({ 'static/*.*': '.' }); |
@@ -94,7 +124,7 @@ module.exports = function(eleventyConfig) { |
94 | 124 | }); |
95 | 125 |
|
96 | 126 | // redirect collection |
97 | | - eleventyConfig.addCollection('redirects', function(collection) { |
| 127 | + eleventyConfig.addCollection('redirects', function (collection) { |
98 | 128 | const redirs = collection.getAll().filter(({ data }) => data.redirect_from); |
99 | 129 | const redirects = new Map(); |
100 | 130 | for (item of redirs) { |
|
0 commit comments