diff --git a/eleventy.config.js b/eleventy.config.js index 6396312..8c8827f 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -2,6 +2,7 @@ import fs from 'node:fs'; import { env } from 'node:process'; import { eleventyImageTransformPlugin } from '@11ty/eleventy-img'; import { feedPlugin } from '@11ty/eleventy-plugin-rss'; +import Image from '@11ty/eleventy-img'; import eleventyPluginCiu from '@alexcarpenter/eleventy-plugin-caniuse'; import eleventyPluginEmbedEverything from 'eleventy-plugin-embed-everything'; import eleventyPluginIcons from 'eleventy-plugin-icons'; @@ -67,7 +68,9 @@ export default async function (eleventyConfig) { eleventyConfig.addPlugin(eleventyImageTransformPlugin, { extensions: 'html', formats: ['avif', 'webp', 'auto'], - sizes: ['1280', '720', '480', 'auto'], + widths: [640, 800, 1280, 1920, 2560, 3840, 'auto'], + urlPath: '/img/', + outputDir: './public/img/', defaultAttributes: { loading: 'lazy', decoding: 'async' @@ -104,6 +107,18 @@ export default async function (eleventyConfig) { ); eleventyConfig.addShortcode('year', () => `${new Date().getFullYear()}`); + eleventyConfig.addShortcode('bgimgset', async (src) => { + const imgset = await Image(src, { + widths: [1920, 2560, 3840], + formats: ['avif', 'webp', 'auto'], + urlPath: '/img/', + outputDir: './public/img/' + }); + + const getSets = ({ url, sourceType }, i) => `url(${url}) type('${sourceType}') ${i + 1}x`; + + return Object.values(imgset).flat().map(getSets); + }); eleventyConfig.addFilter('toDateObj', (dateString) => new Date(dateString)); eleventyConfig.addFilter('isoDate', (dateObj) => dateObj.toISOString()); diff --git a/src/layouts/blogpost.njk b/src/layouts/blogpost.njk index 66f147e..9151b14 100644 --- a/src/layouts/blogpost.njk +++ b/src/layouts/blogpost.njk @@ -3,7 +3,12 @@ layout: base.njk ---
-
+

{{ title }}

diff --git a/src/posts.njk b/src/posts.njk index 9da483b..8af7cf7 100644 --- a/src/posts.njk +++ b/src/posts.njk @@ -20,7 +20,7 @@ pagination: {% if post.data.image and post.data.image.src != '' %} - {{ post.data.image.alt }} + {{ post.data.image.alt }} {% endif %}

{{ post.data.description }}