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

Inline plugin: inline external images #573

Open
scarf005 opened this issue Feb 14, 2024 · 6 comments
Open

Inline plugin: inline external images #573

scarf005 opened this issue Feb 14, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@scarf005
Copy link
Contributor

Enter your suggestions in details:

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

@scarf005 scarf005 added the enhancement New feature or request label Feb 14, 2024
@oscarotero
Copy link
Member

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

@scarf005
Copy link
Contributor Author

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

@oscarotero
Copy link
Member

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
Copy link
Contributor Author

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

@oscarotero
Copy link
Member

You can use Promise.all in the processor:

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

@scarf005
Copy link
Contributor Author

alright, ill take a look this weekends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants