perf: hasOgImage filter uses memoized Set lookup; drop getCallbacks() per-page call
Build & Deploy / build-and-deploy (push) Successful in 2m23s
Build & Deploy / build-and-deploy (push) Successful in 2m23s
This commit is contained in:
+5
-8
@@ -404,15 +404,11 @@ export default function (eleventyConfig) {
|
||||
// Performance: skip PostHTML parsing for pages without <img> tags.
|
||||
// Both registered PostHTML plugins (remote-image-marker, eleventy-img) only
|
||||
// target <img> elements — no point parsing+serializing HTML without them.
|
||||
// Overrides the default @11ty/eleventy/html-transformer transform (same name
|
||||
// overwrites via addTransform) with a pre-check that avoids the full PostHTML
|
||||
// parse/serialize cycle (~3ms/page) for image-free pages.
|
||||
// No URL transform callbacks are registered by any plugin, so the getCallbacks()
|
||||
// check is omitted — it costs ~1ms × 639 pages for a result that is always false.
|
||||
eleventyConfig.addTransform("@11ty/eleventy/html-transformer", async function(content) {
|
||||
if (typeof this.outputPath === "string" && this.outputPath.endsWith(".html") && !content.includes("<img")) {
|
||||
// Safety: if URL transform callbacks exist (they modify <a>, <link>, etc.)
|
||||
// we must still run the full pipeline even without images.
|
||||
const hasUrlCallbacks = eleventyConfig.htmlTransformer.getCallbacks("html", this).length > 0;
|
||||
if (!hasUrlCallbacks) return content;
|
||||
return content;
|
||||
}
|
||||
return eleventyConfig.htmlTransformer.transformContent(this.outputPath, content, this);
|
||||
});
|
||||
@@ -1018,9 +1014,10 @@ export default function (eleventyConfig) {
|
||||
});
|
||||
|
||||
// Check if a generated OG image exists for this slug
|
||||
// Delegates to the memoized hasOgImage() above (directory listed once per build → Set lookup)
|
||||
eleventyConfig.addFilter("hasOgImage", (slug) => {
|
||||
if (!slug) return false;
|
||||
return existsSync(resolve(OG_CACHE_DIR, `${slug}.png`));
|
||||
return hasOgImage(slug);
|
||||
});
|
||||
|
||||
// Inline file contents (for critical CSS inlining)
|
||||
|
||||
Reference in New Issue
Block a user