From 6cc665d8db7e0ad03a869e83c350f2d1b63906e3 Mon Sep 17 00:00:00 2001 From: Stephen Tse Date: Sat, 3 May 2025 18:49:51 -0700 Subject: [PATCH] Removed data-slug requirement for non-preview images --- quartz/plugins/transformers/images.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/quartz/plugins/transformers/images.ts b/quartz/plugins/transformers/images.ts index dda762b40..a37e1093d 100644 --- a/quartz/plugins/transformers/images.ts +++ b/quartz/plugins/transformers/images.ts @@ -77,10 +77,6 @@ const OptimizeImages: Plugin<[Options], HtmlRoot> = (opts: Options) => { if (isAbsoluteURL(src)) return // Skip External images const ext = getFileExtension(src) if (!ext || !supportedImageExts.has(ext)) return - // `data-slug` is set by the OFM markdown transformer. - // This is the absolute file path compared to `src`, which can be relative. - const fullSlug = node.properties["dataSlug"] as FullSlug - if (!fullSlug) return const width = node.properties.width && node.properties.width !== "auto" @@ -100,6 +96,11 @@ const OptimizeImages: Plugin<[Options], HtmlRoot> = (opts: Options) => { // Replace original image source with preview image if custom dimension is defined if (width || height) { + // `data-slug` is set by the OFM markdown transformer. + // This is the absolute file path compared to `src`, which can be relative. + const fullSlug = node.properties["dataSlug"] as FullSlug + if (!fullSlug) return + node.properties.src = src.replace( new RegExp(`(?:${ext}|${targetOptimizedImageExt})$`), `-preview${shouldOptimizeImage ? targetOptimizedImageExt : ext}`,