@apleasantview/eleventy-plugin-baseline 0.1.0-next.14 → 0.1.0-next.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,6 +34,7 @@ function pickRenditions(metadata) {
34
34
  * @param {string} [options.outputDir=DEFAULT_OUTPUT.outputDir] Output directory for generated assets.
35
35
  * @param {string} [options.urlPath=DEFAULT_OUTPUT.urlPath] Public URL base for generated assets.
36
36
  * @param {Object} [options.attrs={}] Extra attributes applied to <img>; `class` merges with imageClass.
37
+ * @param {string} [options.style] Inline style applied to <img> (alias for attrs.style).
37
38
  * @param {boolean} [options.figure=true] Wrap in <figure> when caption is provided.
38
39
  * @param {boolean} [options.setDimensions=true] When false, omit width/height on <img>.
39
40
  */
@@ -45,6 +46,7 @@ export async function imageShortcode(options = {}) {
45
46
  loading = "lazy",
46
47
  containerClass = "",
47
48
  imageClass = "",
49
+ style,
48
50
  widths = DEFAULT_WIDTHS,
49
51
  sizes = DEFAULT_SIZES,
50
52
  formats = DEFAULT_FORMATS,
@@ -62,6 +64,9 @@ export async function imageShortcode(options = {}) {
62
64
  );
63
65
  }
64
66
 
67
+ const normalizedCaption = caption == null ? "" : String(caption);
68
+ const normalizedAlt = alt == null ? "" : String(alt);
69
+
65
70
  const inputDir = this?.eleventy?.directories?.input;
66
71
  const isRemote = /^https?:\/\//i.test(src);
67
72
  const resolvedSrc = !isRemote && inputDir
@@ -99,10 +104,11 @@ export async function imageShortcode(options = {}) {
99
104
 
100
105
  const imageAttributes = {
101
106
  src: lowsrc.url,
102
- alt,
107
+ alt: normalizedAlt,
103
108
  loading,
104
109
  decoding: loading === "eager" ? "sync" : "async",
105
110
  class: combinedClass,
111
+ style,
106
112
  ...(setDimensions ? { width: highsrc.width, height: highsrc.height } : {}),
107
113
  ...restAttrs,
108
114
  "eleventy:ignore": true
@@ -120,10 +126,10 @@ export async function imageShortcode(options = {}) {
120
126
  <img ${imgAttrString}>
121
127
  </picture>`;
122
128
 
123
- if (!figure || !caption) return picture;
129
+ if (!figure || !normalizedCaption) return picture;
124
130
 
125
131
  return `<figure>
126
132
  ${picture}
127
- <figcaption>${caption}</figcaption>
133
+ <figcaption>${normalizedCaption}</figcaption>
128
134
  </figure>`;
129
135
  }
@@ -52,6 +52,19 @@ export default function assetsESBuild(eleventyConfig, options = {}) {
52
52
  // Filter to inline a bundled entry.
53
53
  eleventyConfig.addFilter("inlineESbuild", inlineESbuild);
54
54
 
55
+ // Filter to inline a bundled entry (async, works with callback or promise).
56
+ eleventyConfig.addAsyncFilter("inlineESbuild", async function (jsFilePath, callback) {
57
+ const done = typeof callback === "function" ? callback : null;
58
+ try {
59
+ const html = await inlineESbuild(jsFilePath);
60
+ if (done) return done(null, html);
61
+ return html;
62
+ } catch (error) {
63
+ if (done) return done(error);
64
+ throw error;
65
+ }
66
+ });
67
+
55
68
  // Override the default collection behavior. Adding js as template format and extension collects 11tydata.js files.
56
69
  eleventyConfig.addCollection("all", function (collectionApi) {
57
70
  return collectionApi.getAll().filter(item => {
@@ -3,6 +3,9 @@ import postcss from "postcss";
3
3
  import loadPostCSSConfig from "postcss-load-config";
4
4
  import fallbackPostCSSConfig from "../fallback/postcss.config.js";
5
5
 
6
+ // Resolve user PostCSS config from the project root (cwd), not the Eleventy input dir.
7
+ const configRoot = process.cwd();
8
+
6
9
  export default async function inlinePostCSS(cssFilePath) {
7
10
  try {
8
11
  let cssContent = await fs.readFile(cssFilePath, 'utf8');
@@ -15,7 +18,9 @@ export default async function inlinePostCSS(cssFilePath) {
15
18
  ({ plugins, options } = await loadPostCSSConfig({}, configRoot));
16
19
  } catch (error) {
17
20
  // If none is found, fall back to the bundled Baseline config to keep builds working.
18
- ({plugins, ...options } = fallbackPostCSSConfig);
21
+ const { plugins: fallbackPlugins, ...fallbackOptions } = fallbackPostCSSConfig;
22
+ plugins = fallbackPlugins;
23
+ options = fallbackOptions;
19
24
  }
20
25
 
21
26
  let result = await postcss(plugins).process(cssContent, {
@@ -57,6 +57,16 @@ export default function assetsPostCSS(eleventyConfig) {
57
57
  }
58
58
  });
59
59
 
60
- // Filter to inline a bundled entry.
61
- eleventyConfig.addFilter("inlinePostCSS", inlinePostCSS);
60
+ // Filter to inline a bundled entry; supports callback style (Nunjucks/Liquid) and Promise return.
61
+ eleventyConfig.addAsyncFilter("inlinePostCSS", async function (cssFilePath, callback) {
62
+ const done = typeof callback === "function" ? callback : null;
63
+ try {
64
+ const html = await inlinePostCSS(cssFilePath);
65
+ if (done) return done(null, html);
66
+ return html;
67
+ } catch (error) {
68
+ if (done) return done(error);
69
+ throw error;
70
+ }
71
+ });
62
72
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apleasantview/eleventy-plugin-baseline",
3
- "version": "0.1.0-next.14",
3
+ "version": "0.1.0-next.16",
4
4
  "description": "An experimental Swiss army knife toolkit for Eleventy",
5
5
  "type": "module",
6
6
  "main": "eleventy.config.js",