fix for rebuilds
This commit is contained in:
parent
ca9e1593a9
commit
e6ca567597
2 changed files with 2 additions and 54 deletions
|
@ -1,51 +0,0 @@
|
||||||
const path = require("path");
|
|
||||||
const eleventyImage = require("@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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = function(eleventyConfig) {
|
|
||||||
// Eleventy Image shortcode
|
|
||||||
// https://www.11ty.dev/docs/plugins/image/
|
|
||||||
eleventyConfig.addAsyncShortcode("image", async function imageShortcode(src, alt, widths, sizes) {
|
|
||||||
// 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, {
|
|
||||||
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
|
|
||||||
let imageAttributes = {
|
|
||||||
alt,
|
|
||||||
sizes,
|
|
||||||
loading: "lazy",
|
|
||||||
decoding: "async",
|
|
||||||
};
|
|
||||||
|
|
||||||
return eleventyImage.generateHTML(metadata, imageAttributes);
|
|
||||||
});
|
|
||||||
};
|
|
|
@ -8,7 +8,6 @@ const pluginNavigation = require("@11ty/eleventy-navigation");
|
||||||
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");
|
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");
|
||||||
|
|
||||||
const pluginDrafts = require("./eleventy.config.drafts.js");
|
const pluginDrafts = require("./eleventy.config.drafts.js");
|
||||||
const pluginImages = require("./eleventy.config.images.js");
|
|
||||||
|
|
||||||
/** @param {import('@11ty/eleventy').UserConfig} eleventyConfig */
|
/** @param {import('@11ty/eleventy').UserConfig} eleventyConfig */
|
||||||
module.exports = function(eleventyConfig) {
|
module.exports = function(eleventyConfig) {
|
||||||
|
@ -18,13 +17,13 @@ module.exports = function(eleventyConfig) {
|
||||||
"./public/": "/",
|
"./public/": "/",
|
||||||
"./node_modules/prismjs/themes/prism-okaidia.css": "/css/prism-okaidia.css"
|
"./node_modules/prismjs/themes/prism-okaidia.css": "/css/prism-okaidia.css"
|
||||||
});
|
});
|
||||||
eleventyConfig.addPassthroughCopy("**/*.png");
|
eleventyConfig.addPassthroughCopy("src/**/*.png");
|
||||||
|
|
||||||
// Run Eleventy when these files change:
|
// Run Eleventy when these files change:
|
||||||
// https://www.11ty.dev/docs/watch-serve/#add-your-own-watch-targets
|
// https://www.11ty.dev/docs/watch-serve/#add-your-own-watch-targets
|
||||||
|
|
||||||
// Watch content images for the image pipeline.
|
// Watch content images for the image pipeline.
|
||||||
// eleventyConfig.addWatchTarget("content/**/*.{svg,webp,png,jpeg}");
|
eleventyConfig.addWatchTarget("content/**/*.{svg,webp,png,jpeg}");
|
||||||
|
|
||||||
// App plugins
|
// App plugins
|
||||||
eleventyConfig.addPlugin(pluginDrafts);
|
eleventyConfig.addPlugin(pluginDrafts);
|
||||||
|
|
Loading…
Reference in a new issue