Skip to content

Commit

Permalink
Also copy images in HTML tags to static directory
Browse files Browse the repository at this point in the history
  • Loading branch information
MartenBE authored and webpro committed Aug 31, 2024
1 parent 6d89d70 commit 358f162
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import featuredSlide from './featured-slide.js';

const files = new Set();

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

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

Expand Down Expand Up @@ -74,9 +75,10 @@ const copyAssetsAndWriteFile = async (sourceDir, file, targetDir) => {
const base = relativeDir(file, '.');
const markup = await renderFile(path.join(sourceDir, file), { base });

const images = markdown.matchAll(htmlImageRE);
const backgroundImages = markdown.matchAll(htmlImageBackgroundRE);
const allImages = [...images, ...backgroundImages];
const markdownImages = markdown.matchAll(markdownImageRE);
const htmlImages = markdown.matchAll(htmlImageRE);
const backgroundImages = markdown.matchAll(markdownImageBackgroundRE);
const allImages = [...markdownImages, ...htmlImages, ...backgroundImages];

for (let image of allImages) {
const [, imgPath] = image;
Expand Down

0 comments on commit 358f162

Please sign in to comment.