Skip to content

Commit ecea5df

Browse files
committed
Add support to WebC for console output.
1 parent f5c3028 commit ecea5df

5 files changed

+24
-17
lines changed

eleventy-image.webc

+8
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ async function imagePlugin(attributes, globalPluginOptions) {
9898

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

101+
// see Util.addConfig
102+
if(globalPluginOptions.eleventyConfig) {
103+
Object.defineProperty(options, "eleventyConfig", {
104+
value: globalPluginOptions.eleventyConfig,
105+
enumerable: false,
106+
});
107+
}
108+
101109
let metadata = await imagePackage(src, options);
102110

103111
let imageAttributes = Object.assign({}, defaultGlobalAttributes, attributes);

src/global-options.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require("path");
2+
const Util = require("./util.js");
23

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

12-
// globalOptions.eleventyConfig = eleventyConfig;
1313
globalOptions.directories = directories;
1414
globalOptions.generatedVia = via;
1515

16-
Object.defineProperty(globalOptions, "eleventyConfig", {
17-
value: eleventyConfig,
18-
enumerable: false,
19-
});
16+
Util.addConfig(eleventyConfig, globalOptions);
2017

2118
return globalOptions;
2219
}

src/image-attrs-to-posthtml-node.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const eleventyImage = require("../img.js");
2+
const Util = require("./util.js");
23

34
const ATTR_PREFIX = "eleventy:";
45

@@ -57,13 +58,8 @@ async function imageAttributesToPosthtmlNode(attributes, instanceOptions, global
5758
}
5859
}
5960

60-
let cfg = globalPluginOptions.eleventyConfig;
6161
let options = Object.assign({}, globalPluginOptions, instanceOptions);
62-
63-
Object.defineProperty(options, "eleventyConfig", {
64-
value: cfg,
65-
enumerable: false,
66-
});
62+
Util.addConfig(globalPluginOptions.eleventyConfig, options);
6763

6864
let metadata = await eleventyImage(attributes.src, options);
6965
let imageAttributes = Object.assign({}, globalPluginOptions.defaultAttributes, attributes);

src/on-request-during-serve-plugin.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,7 @@ function eleventyImageOnRequestDuringServePlugin(eleventyConfig, options = {}) {
4848
generatedVia: Util.KEYS.requested,
4949
});
5050

51-
if(eleventyConfig) {
52-
Object.defineProperty(opts, "eleventyConfig", {
53-
value: eleventyConfig,
54-
enumerable: false,
55-
});
56-
}
51+
Util.addConfig(eleventyConfig, opts);
5752

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

src/util.js

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ class Util {
5151
static isRequested(generatedVia) {
5252
return generatedVia === this.KEYS.requested;
5353
}
54+
55+
static addConfig(eleventyConfig, options) {
56+
if(!eleventyConfig) {
57+
return;
58+
}
59+
60+
Object.defineProperty(options, "eleventyConfig", {
61+
value: eleventyConfig,
62+
enumerable: false,
63+
});
64+
}
5465
}
5566

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

0 commit comments

Comments
 (0)