Skip to content

Commit

Permalink
<Image>コンポーネントにSVGが与えられたときはsrcsetを生成しないよう修正
Browse files Browse the repository at this point in the history
  • Loading branch information
ciffelia committed Dec 5, 2023
1 parent 93acd90 commit 1f5d88f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/common/Image.astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = Omit<HTMLAttributes<'img'>, 'src' | 'srcset'> & {
const { widths = [3840, 1920, 960, 480, 240], ...attrs } = Astro.props
const { src, attributes } = await getImage(attrs)
const { src, options, attributes } = await getImage(attrs)
const originalWidth = parseInt(attributes.width, 10)
const srcset = (
Expand All @@ -25,4 +25,14 @@ const srcset = (
).join(',')
---

<img src={src} srcset=`${src} ${originalWidth}w,${srcset}` {...attributes} />
{
options.format === 'svg' ? (
<img src={src} {...attributes} />
) : (
<img
src={src}
srcset={`${src} ${originalWidth}w,${srcset}`}
{...attributes}
/>
)
}

0 comments on commit 1f5d88f

Please sign in to comment.