From 393f1f4012ea229f7e335b3859ae8eaa10eba0a8 Mon Sep 17 00:00:00 2001 From: Martijn <1958780+MartenBE@users.noreply.github.com> Date: Sun, 5 Nov 2023 20:44:46 +0100 Subject: [PATCH] --static now also copies background images (#461) --- lib/static.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/static.js b/lib/static.js index 3329819..35da587 100644 --- a/lib/static.js +++ b/lib/static.js @@ -20,6 +20,7 @@ const featuredSlide = require('./featured-slide'); const files = new Set(); const htmlImageRE = //g; +const htmlImageBackgroundRE = /data-background-image=["'](.+?)["']/g; const relativeDir = (from, to) => path.relative(from, to).replace(/^\.\./, '.'); @@ -71,9 +72,12 @@ const copyAssetsAndWriteFile = async (sourceDir, file, targetDir) => { const base = relativeDir(file, '.'); const markup = await renderFile(path.join(sourceDir, file), { base }); - let image; const html = md.marked(markdown.toString()); - while ((image = htmlImageRE.exec(html))) { + const images = html.matchAll(htmlImageRE); + const backgroundImages = html.matchAll(htmlImageBackgroundRE); + const allImages = [...images, ...backgroundImages]; + + for (let image of allImages) { const [, imgPath] = image; if (!isAbsoluteURL(imgPath)) { const relPath = path.join(path.dirname(file), imgPath);