How to generate html page for each image file? #467
-
I have a lots of images structured in lots of dirrectories. Basically what I want is to create a html page for each image to just display optimized image. // _config.js
import lume from "lume/mod.ts";
import imagick from "lume/plugins/imagick.ts";
import {JsxEngine} from "lume/plugins/jsx.ts";
import picture from "lume/plugins/picture.ts";
import resolveUrls from "lume/plugins/resolve_urls.ts";
const site = lume();
site.use(picture());
site.use(imagick());
site.use(resolveUrls());
// This loader should just generate HTML for image.
function loader(path) {
return {content: `<img src="${path}" imagick="avif webp png 300"/>`};
}
site.loadPages(['.jpeg', '.png'], loader, new JsxEngine(site.src("/"))) The build correctly processes all files, creates HTML for each image. However, I'm missing something, and I don't understand what, because the imagik plugin can't find or process the image correctly. Error: Error processing page
- page: /img/інше/IMG_2321.png
- processor: imagick
...
Caused by Error: UnableToOpenBlob '<div><img src="C:/Users/kozac/dev/blog_kyivska_zefirka/img/інше/IMG_2321.png" imagick="avif webp png 300"/></div>': No such file or directory @ error/blob.c/OpenBlob/3569 And in output I'm getting html files for each image but I'm not getting optimized images itself. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
This is because your loader returns html code, not the image content. You can create a function to return the images and use a page generator to create the html pages. Example (not tested): // _config.js
// function to return an array of all images loaded
site.data("get_images", function () {
return site.pages
.filter((page) => page.data.url.match(/\.(jpg|jpeg|png)$/))
.map((page) => page.data.url);
}); // images.tmpl.js
export default function* ({ get_images }) {
for (const image of get_images()) {
yield {
url: image + ".html",
content: `<img src="${image}" imagick="avif webp png 300"/>`
}
}
} Probably this could be even easier if the |
Beta Was this translation helpful? Give feedback.
This is because your loader returns html code, not the image content.
You can create a function to return the images and use a page generator to create the html pages. Example (not tested):
Probably this could be even e…