Skip to content

Commit

Permalink
If you pass in your eleventyConfig in your Image options, you’ll get …
Browse files Browse the repository at this point in the history
…support for console output (via shortcode method)
  • Loading branch information
zachleat committed May 11, 2024
1 parent ecea5df commit d7303ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 12 additions & 3 deletions img.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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")) {

Check failure on line 798 in img.js

View workflow job for this annotation

GitHub Actions / Node.js 18 on ubuntu-latest

Do not access Object.prototype method 'propertyIsEnumerable' from target object

Check failure on line 798 in img.js

View workflow job for this annotation

GitHub Actions / Node.js 20 on ubuntu-latest

Do not access Object.prototype method 'propertyIsEnumerable' from target object
delete opts.eleventyConfig;
Util.addConfig(eleventyConfig, opts);
}

let img = new Image(src, opts);


let key;
let resolvedOptions = img.options;

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/on-request-during-serve-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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: {
Expand Down

0 comments on commit d7303ed

Please sign in to comment.