Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy img in html tag #496

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Loading