lumeland / lume

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

webp asset files corrupted on build #620

Closed quadratz closed 2 weeks ago

quadratz commented 3 weeks ago

Version

v2.2.1

Platform

Linux

What steps will reproduce the bug?

Steps:

  1. Create a folder called assets at the root of the project. Move all webp files there.
  2. Add site.loadAssets([".webp"]) to _config.ts.
  3. Run deno task build.
  4. All of the webp files built are corrupted; their file sizes have changed, and they cannot be opened by the image viewer.

The reproduction repository is available at https://github.com/quadratz/lume-issue.

How often does it reproduce? Is there a required condition?

How often does it reproduce?

Always.

Is there a required condition?

Not sure.

What is the expected behavior?

The build result of webp should not changed because there is no process happens.

What do you see instead?

The webp files produced after building have a larger size than the originals, and they are also corrupted.

Additional information

The reproduction repository is available at https://github.com/quadratz/lume-issue.

oscarotero commented 3 weeks ago

site.loadAssets() needs the loader as the second argument. If it's not specified, it uses the text loader, but for binary files, you have to pass the binary loader:

import lume from "lume/mod.ts";
import binary from "lume/core/loaders/binary.ts";

const site = lume();

site.loadAssets([".webp"], binary);

export default site;

I'm planning to detect automatically the proper loader based on the file extension. But it's not implemented yet.

quadratz commented 2 weeks ago

Thank you. I can confirm that adding the binary loader solves the issue. Perhaps we should add this information to the documentation.

oscarotero commented 2 weeks ago

Good idea. Thanks for the PR on lume.land!