From d7303edb00ca12a192cd35afc401deb153fffac0 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Fri, 10 May 2024 20:47:07 -0500 Subject: [PATCH] =?UTF-8?q?If=20you=20pass=20in=20your=20eleventyConfig=20?= =?UTF-8?q?in=20your=20Image=20options,=20you=E2=80=99ll=20get=20support?= =?UTF-8?q?=20for=20console=20output=20(via=20shortcode=20method)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- img.js | 15 ++++++++++++--- src/on-request-during-serve-plugin.js | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/img.js b/img.js index 8c19431..e96c0e1 100644 --- a/img.js +++ b/img.js @@ -747,13 +747,13 @@ function logProcessedMessage(eleventyConfig, src, opts) { } eleventyConfig.logger.logWithOptions({ - message: `Processing ${logSrc} (${opts.generatedVia})`, + message: `Processing ${logSrc}${opts.generatedVia ? ` (${opts.generatedVia})` : ""}`, prefix: "[11ty/eleventy-img]" }); } function setupLogger(eleventyConfig, opts) { - if(typeof eleventyConfig?.logger?.logWithOptions !== "function" || Util.isRequested(opts.generatedVia)) { + if(typeof eleventyConfig?.logger?.logWithOptions !== "function" || Util.isRequested(opts?.generatedVia)) { return; } @@ -794,8 +794,15 @@ function setupLogger(eleventyConfig, opts) { } function queueImage(src, opts) { - let img = new Image(src, opts); let eleventyConfig = opts?.eleventyConfig; + if(opts?.eleventyConfig && opts.propertyIsEnumerable("eleventyConfig")) { + delete opts.eleventyConfig; + Util.addConfig(eleventyConfig, opts); + } + + let img = new Image(src, opts); + + let key; let resolvedOptions = img.options; @@ -887,6 +894,8 @@ module.exports.getHash = function getHash(src, options) { return img.getHash(); }; +module.exports.setupLogger = setupLogger; + const generateHTML = require("./src/generate-html.js"); module.exports.generateHTML = generateHTML; module.exports.generateObject = generateHTML.generateObject; diff --git a/src/on-request-during-serve-plugin.js b/src/on-request-during-serve-plugin.js index 48e3360..057721b 100644 --- a/src/on-request-during-serve-plugin.js +++ b/src/on-request-during-serve-plugin.js @@ -2,6 +2,7 @@ const fs = require("fs"); const { TemplatePath } = require("@11ty/eleventy-utils"); const eleventyImage = require("../img.js"); +const setupLogger = eleventyImage.setupLogger; const Util = require("./util.js"); const debug = require("debug")("Eleventy:Image"); @@ -14,6 +15,8 @@ function eleventyImageOnRequestDuringServePlugin(eleventyConfig, options = {}) { console.log( `[11ty/eleventy-img] Warning: your version of Eleventy is incompatible with the dynamic image rendering plugin (see \`eleventyImageOnRequestDuringServePlugin\`). Any dynamically rendered images will 404 (be missing) during --serve mode but will not affect the standard build output: ${e.message}` ); } + setupLogger(eleventyConfig, {}); + // Eleventy 3.0 or newer only. eleventyConfig.setServerOptions({ onRequest: {