Skip to content

How to generate html page for each image file? #467

Answered by oscarotero
cawa-93 asked this question in Q&A
Discussion options

You must be logged in to vote

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 e…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@cawa-93
Comment options

@oscarotero
Comment options

@cawa-93
Comment options

@oscarotero
Comment options

@oscarotero
Comment options

Answer selected by cawa-93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants