lumeland / lume

🔥 Static site generator for Deno 🦕
https://lume.land
MIT License
1.75k stars 74 forks source link

Inline plugin: inline external images #573

Open scarf005 opened 4 months ago

scarf005 commented 4 months ago

Enter your suggestions in details:

in lume external images have significant downsides to local images due to not being able to use image plugins.

oscarotero commented 4 months ago

You can use remote files for that: https://lume.land/docs/core/remote-files/

scarf005 commented 4 months ago

would it be possible to use any remote images as remote files? (e.g via regex or preprocess plugin)

oscarotero commented 4 months ago

I guess you can create a processor to download remote images and convert them to pages. A very simple example (needs much more work, like caching etc).

site.process([".html"], (pages, allPages) => {
  for (const page of pages) {
    const externalImages = page.document.querySelectorAll("img[src^='https://']");
    for (const img of externalImages) {
      const response = await fetch(img.getAttribute("src"));
      const content = new Uint8Array(await response.arrayBuffer());
      allPages.push(Page.create({
        url: //generate filename using the image url
        content,
      });
    }
  }
});
scarf005 commented 4 months ago

does lume support some kind of 'async queue' to queue long tasks and await promise.all them later?

oscarotero commented 4 months ago

You can use Promise.all in the processor:

site.process([".html"], async (pages, allPages) => {
  await Promise.all(pages.map((page) => ... ));
});
scarf005 commented 4 months ago

alright, ill take a look this weekends.