Skip to content

Commit

Permalink
remove empty srcset and sizes attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchell Christ committed Oct 22, 2024
1 parent c9519a8 commit 755e28f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/ui/Img.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,20 @@ function generateSrcset(
const filtered = sizes.filter((size) => !width || size <= width)

return {
srcSet: filtered
.map(
(size) => `${urlFor(image).width(size).auto('format').url()} ${size}w`,
)
.join(', '),
srcSet:
filtered
.map(
(size) =>
`${urlFor(image).width(size).auto('format').url()} ${size}w`,
)
.join(', ') || undefined,

sizes: filtered
.map(
(size, i) =>
`${i < filtered.length - 1 ? `(max-width: ${size + 1}px) ` : ''}${size}px`,
)
.join(', '),
sizes:
filtered
.map(
(size, i) =>
`${i < filtered.length - 1 ? `(max-width: ${size + 1}px) ` : ''}${size}px`,
)
.join(', ') || undefined,
}
}

0 comments on commit 755e28f

Please sign in to comment.