mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 16:51:37 +00:00
Add support image lazyloading
This commit is contained in:
@ -3,10 +3,15 @@ import NextImage, { ImageProps } from 'next/image';
|
||||
interface Props extends ImageProps {}
|
||||
|
||||
const Image = ({ alt, ...rest }: Props) => {
|
||||
const supportImg = ['jpeg', 'png', 'webp', 'avif'];
|
||||
const placeholder = supportImg.includes((rest.src as { src: string }).src)
|
||||
? 'blur'
|
||||
: 'empty';
|
||||
|
||||
return (
|
||||
<>
|
||||
<span className="block text-center">
|
||||
<NextImage alt={alt} placeholder="blur" {...rest} />
|
||||
<NextImage alt={alt} placeholder={placeholder} {...rest} />
|
||||
{alt && <span className="block text-center text-gray-400">{alt}</span>}
|
||||
</span>
|
||||
</>
|
||||
|
Reference in New Issue
Block a user