Skip to content

Commit

Permalink
Add support to WebC for console output.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed May 11, 2024
1 parent f5c3028 commit ecea5df
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
8 changes: 8 additions & 0 deletions eleventy-image.webc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ async function imagePlugin(attributes, globalPluginOptions) {

let options = Object.assign({}, globalPluginOptions, instanceOptions);

// see Util.addConfig
if(globalPluginOptions.eleventyConfig) {
Object.defineProperty(options, "eleventyConfig", {
value: globalPluginOptions.eleventyConfig,
enumerable: false,
});
}

let metadata = await imagePackage(src, options);

let imageAttributes = Object.assign({}, defaultGlobalAttributes, attributes);
Expand Down
7 changes: 2 additions & 5 deletions src/global-options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require("path");
const Util = require("./util.js");

function getGlobalOptions(eleventyConfig, options, via) {
let directories = eleventyConfig.directories;
Expand All @@ -9,14 +10,10 @@ function getGlobalOptions(eleventyConfig, options, via) {
outputDir: path.join(directories.output, options.urlPath || ""),
}, options);

// globalOptions.eleventyConfig = eleventyConfig;
globalOptions.directories = directories;
globalOptions.generatedVia = via;

Object.defineProperty(globalOptions, "eleventyConfig", {
value: eleventyConfig,
enumerable: false,
});
Util.addConfig(eleventyConfig, globalOptions);

return globalOptions;
}
Expand Down
8 changes: 2 additions & 6 deletions src/image-attrs-to-posthtml-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const eleventyImage = require("../img.js");
const Util = require("./util.js");

const ATTR_PREFIX = "eleventy:";

Expand Down Expand Up @@ -57,13 +58,8 @@ async function imageAttributesToPosthtmlNode(attributes, instanceOptions, global
}
}

let cfg = globalPluginOptions.eleventyConfig;
let options = Object.assign({}, globalPluginOptions, instanceOptions);

Object.defineProperty(options, "eleventyConfig", {
value: cfg,
enumerable: false,
});
Util.addConfig(globalPluginOptions.eleventyConfig, options);

let metadata = await eleventyImage(attributes.src, options);
let imageAttributes = Object.assign({}, globalPluginOptions.defaultAttributes, attributes);
Expand Down
7 changes: 1 addition & 6 deletions src/on-request-during-serve-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ function eleventyImageOnRequestDuringServePlugin(eleventyConfig, options = {}) {
generatedVia: Util.KEYS.requested,
});

if(eleventyConfig) {
Object.defineProperty(opts, "eleventyConfig", {
value: eleventyConfig,
enumerable: false,
});
}
Util.addConfig(eleventyConfig, opts);

debug( `%o transformed on request to %o at %o width.`, src, imageFormat, width );

Expand Down
11 changes: 11 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ class Util {
static isRequested(generatedVia) {
return generatedVia === this.KEYS.requested;
}

static addConfig(eleventyConfig, options) {
if(!eleventyConfig) {
return;
}

Object.defineProperty(options, "eleventyConfig", {
value: eleventyConfig,
enumerable: false,
});
}
}

// Temporary alias for changes made in https://github.com/11ty/eleventy-img/pull/138
Expand Down

0 comments on commit ecea5df

Please sign in to comment.