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

--static now also copies background images #461

Merged
merged 1 commit into from
Nov 5, 2023
Merged
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
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
Loading