Use new Image optimization transform
This commit is contained in:
parent
ceebb3ad44
commit
6c04d6038d
@ -8,7 +8,7 @@ Leverage agile frameworks to provide a robust synopsis for high level overviews.
|
|||||||
|
|
||||||
Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.
|
Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.
|
||||||
|
|
||||||
{% image "./possum.png", "A possum parent and two possum kids hanging from the iconic red balloon" %}
|
<img src="./possum.png" alt="A possum parent and two possum kids hanging from the iconic red balloon">
|
||||||
|
|
||||||
## Section Header
|
## Section Header
|
||||||
|
|
||||||
|
@ -1,51 +1,28 @@
|
|||||||
import path from "path";
|
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
|
||||||
import eleventyImage from "@11ty/eleventy-img";
|
|
||||||
|
|
||||||
function relativeToInputPath(inputPath, relativeFilePath) {
|
|
||||||
let split = inputPath.split("/");
|
|
||||||
split.pop();
|
|
||||||
|
|
||||||
return path.resolve(split.join(path.sep), relativeFilePath);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function isFullUrl(url) {
|
|
||||||
try {
|
|
||||||
new URL(url);
|
|
||||||
return true;
|
|
||||||
} catch(e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function(eleventyConfig) {
|
export default function(eleventyConfig) {
|
||||||
// Eleventy Image shortcode
|
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
|
||||||
// https://www.11ty.dev/docs/plugins/image/
|
// which file extensions to process
|
||||||
eleventyConfig.addAsyncShortcode("image", async function imageShortcode(src, alt, widths, sizes) {
|
extensions: "html",
|
||||||
// Full list of formats here: https://www.11ty.dev/docs/plugins/image/#output-formats
|
|
||||||
// Warning: Avif can be resource-intensive so take care!
|
|
||||||
let formats = ["avif", "webp", "auto"];
|
|
||||||
let input;
|
|
||||||
if(isFullUrl(src)) {
|
|
||||||
input = src;
|
|
||||||
} else {
|
|
||||||
input = relativeToInputPath(this.page.inputPath, src);
|
|
||||||
}
|
|
||||||
|
|
||||||
let metadata = await eleventyImage(input, {
|
formats: ["avif", "webp", "auto"],
|
||||||
widths: widths || ["auto"],
|
|
||||||
formats,
|
|
||||||
outputDir: path.join(eleventyConfig.dir.output, "img"), // Advanced usage note: `eleventyConfig.dir` works here because we’re using addPlugin.
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO loading=eager and fetchpriority=high
|
// widths: ["auto"],
|
||||||
let imageAttributes = {
|
|
||||||
alt,
|
// urlPath: "/img/",
|
||||||
sizes,
|
|
||||||
|
// If a urlPath is not specified:
|
||||||
|
|
||||||
|
// 1. Relative image sources (<img src="./possum.png">) will be co-located in your output directory
|
||||||
|
// with the template they are used in. Warning: if the same source image is used in multiple templates,
|
||||||
|
// it will be written to two different locations!
|
||||||
|
// 2. Absolute image sources (<img src="/possum.png">) will be normalized to your input/content directory
|
||||||
|
// and written to ${OUTPUT_DIR}/img/
|
||||||
|
|
||||||
|
// <img loading decoding> assigned on the HTML tag will override these values.
|
||||||
|
defaultAttributes: {
|
||||||
loading: "lazy",
|
loading: "lazy",
|
||||||
decoding: "async",
|
decoding: "async"
|
||||||
};
|
}
|
||||||
|
|
||||||
return eleventyImage.generateHTML(metadata, imageAttributes);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { DateTime } from "luxon";
|
import { DateTime } from "luxon";
|
||||||
import markdownItAnchor from "markdown-it-anchor";
|
import markdownItAnchor from "markdown-it-anchor";
|
||||||
|
|
||||||
import { PathToUrlTransformPlugin, HtmlBasePlugin } from "@11ty/eleventy";
|
import { InputPathToUrlTransformPlugin, HtmlBasePlugin } from "@11ty/eleventy";
|
||||||
import pluginRss from "@11ty/eleventy-plugin-rss";
|
import pluginRss from "@11ty/eleventy-plugin-rss";
|
||||||
import pluginSyntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
|
import pluginSyntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
|
||||||
import pluginBundle from "@11ty/eleventy-plugin-bundle";
|
import pluginBundle from "@11ty/eleventy-plugin-bundle";
|
||||||
@ -35,10 +35,9 @@ export default async function(eleventyConfig) {
|
|||||||
preAttributes: { tabindex: 0 }
|
preAttributes: { tabindex: 0 }
|
||||||
});
|
});
|
||||||
eleventyConfig.addPlugin(pluginNavigation);
|
eleventyConfig.addPlugin(pluginNavigation);
|
||||||
|
|
||||||
eleventyConfig.addPlugin(pluginBundle);
|
eleventyConfig.addPlugin(pluginBundle);
|
||||||
eleventyConfig.addPlugin(HtmlBasePlugin);
|
eleventyConfig.addPlugin(HtmlBasePlugin);
|
||||||
eleventyConfig.addPlugin(PathToUrlTransformPlugin);
|
eleventyConfig.addPlugin(InputPathToUrlTransformPlugin);
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
|
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14"
|
"node": ">=18"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"type": "opencollective",
|
"type": "opencollective",
|
||||||
@ -33,8 +33,8 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/11ty/eleventy-base-blog#readme",
|
"homepage": "https://github.com/11ty/eleventy-base-blog#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@11ty/eleventy": "file:../eleventy",
|
"@11ty/eleventy": "3.0.0-alpha.5",
|
||||||
"@11ty/eleventy-img": "^3.1.8",
|
"@11ty/eleventy-img": "^4.0.2",
|
||||||
"@11ty/eleventy-navigation": "^0.3.5",
|
"@11ty/eleventy-navigation": "^0.3.5",
|
||||||
"@11ty/eleventy-plugin-bundle": "^1.0.5",
|
"@11ty/eleventy-plugin-bundle": "^1.0.5",
|
||||||
"@11ty/eleventy-plugin-rss": "^1.2.0",
|
"@11ty/eleventy-plugin-rss": "^1.2.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user