feat: add placeholder for images with invalid src
This commit is contained in:
parent
2baba97451
commit
0e3ef370c7
3 changed files with 30 additions and 3 deletions
|
@ -14,10 +14,15 @@ const imageShortcode = async (
|
|||
alt = "",
|
||||
caption = "",
|
||||
className = undefined,
|
||||
placeholder = "",
|
||||
widths = [400, 800, 1280],
|
||||
formats = ["webp", "jpeg"],
|
||||
sizes = "100vw",
|
||||
) => {
|
||||
if (!src) {
|
||||
return `<div class="image-placeholder">${placeholder}</div>`;
|
||||
}
|
||||
|
||||
const metadata = await Image(src, {
|
||||
widths: [...widths, null],
|
||||
formats: [...formats, null],
|
||||
|
@ -26,6 +31,9 @@ const imageShortcode = async (
|
|||
sharpOptions: {
|
||||
animated: true,
|
||||
},
|
||||
cacheOptions: {
|
||||
duration: "7d",
|
||||
},
|
||||
});
|
||||
|
||||
const lowsrc = metadata.jpeg[metadata.jpeg.length - 1];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue