Skip to content

Commit

Permalink
--static now also copies background images (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartenBE authored Nov 5, 2023
1 parent be9dd11 commit 393f1f4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const featuredSlide = require('./featured-slide');
const files = new Set();

const htmlImageRE = /<img.+src=["'](.+?)["'](?:.+?)>/g;
const htmlImageBackgroundRE = /data-background-image=["'](.+?)["']/g;

const relativeDir = (from, to) => path.relative(from, to).replace(/^\.\./, '.');

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 393f1f4

Please sign in to comment.