feat: adds datocms astro image - #355
JopMolenaar wants to merge 16 commits into
Conversation
5fd9f58 to
44bb9f9
Compare
| import type { ImageBlockFragment } from '~/lib/datocms/types'; | ||
| import { t } from '~/lib/i18n'; | ||
|
|
||
| const defaultSizes = [1280, 960, 640, 320]; |
There was a problem hiding this comment.
The default way is with DPR now. Do we want to set our own DPR values? Or are the DatoCMS default sufficient?
srcSetCandidates = [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4]
| }; | ||
| type Props = HTMLAttributes<'figure'> & { | ||
| image: ImageBlockFragment['image'] | ||
| priority?: boolean |
There was a problem hiding this comment.
priority is consistant with the DatoCMS Image component. Should we keep my change or revert it to loading?
| url | ||
| responsiveImage { | ||
| aspectRatio | ||
| responsiveImage( imgixParams: { auto: [format, compress], q: 80, fit: max, w: 1200} ) { |
There was a problem hiding this comment.
Where is the 1200 width coming from? Max width of the default text block layout?
Either way I don't think we want to have imgix params here but instead closer to the component, probably passed down from the text block layout?
There was a problem hiding this comment.
The q: 80, fit: max, w: 1200 is set here to have more control over the biggest image. Before this change we made our own srcSet steps, but now this is done with dpr. But wiuth only dpr we have no control over the largest possible img?
I think this place for the imgix params is the most logic place? The src set breakpoints also depend on this width. So if we set w after getting the srcSets, we get other breakpoints then that we serve?
srcSets when we append all imgix variables in the imgae.astro:
<source srcset="
https://www.datocms-assets.com/145765/1730394116-head-start-cover.jpg?dpr=0.25&auto=format%2Ccompress&q=80&w=1200&fit=max 482w,
https://www.datocms-assets.com/145765/1730394116-head-start-cover.jpg?dpr=0.5&auto=format%2Ccompress&q=80&w=1200&fit=max 965w,
https://www.datocms-assets.com/145765/1730394116-head-start-cover.jpg?dpr=0.75&auto=format%2Ccompress&q=80&w=1200&fit=max 1447w,
https://www.datocms-assets.com/145765/1730394116-head-start-cover.jpg?auto=format%2Ccompress&q=80&w=1200&fit=max 1930w"
sizes="(max-width: 1930px) 100vw, 1930px">
srcSets when we set max width in the query:
<source srcset="
https://www.datocms-assets.com/145765/1730394116-head-start-cover.jpg?dpr=0.25&w=1200&auto=format%2Ccompress&q=80&fit=max 300w,
https://www.datocms-assets.com/145765/1730394116-head-start-cover.jpg?dpr=0.5&w=1200&auto=format%2Ccompress&q=80&fit=max 600w,
https://www.datocms-assets.com/145765/1730394116-head-start-cover.jpg?dpr=0.75&w=1200&auto=format%2Ccompress&q=80&fit=max 900w,
https://www.datocms-assets.com/145765/1730394116-head-start-cover.jpg?w=1200&auto=format%2Ccompress&q=80&fit=max 1200w,
https://www.datocms-assets.com/145765/1730394116-head-start-cover.jpg?dpr=1.5&w=1200&auto=format%2Ccompress&q=80&fit=max 1800w"
sizes="(max-width: 1200px) 100vw, 1200px">
af4b8df to
95e7997
Compare
- Reuse HTMLAttributes<'figure'> for forwarded props; add typed imageProps escape hatch (omits data/imgClass/priority) - Replace `loading` prop with `priority: boolean` to mirror the DatoCMS AstroImage API; vector path applies the same fetchpriority/loading pattern - Add decoding="async" to vector img path - Avoid mutating input prop: use const alt = image.alt ?? '' and forward alt into responsiveImage data - Scope CSS under .image-block, merge duplicate selectors, use define:vars for the unavailable message Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The unavailable-message exposed via `define:vars` is consumed inside a `content` declaration, which requires a quoted string. Without quotes the declaration was invalid and the `::after` pseudo never rendered. Use JSON.stringify to produce a valid CSS string literal and handle any embedded quotes/backslashes safely. Also collapse the duplicate `.image-block__image` selector into a nested rule. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The vector `<img>` path has no inline sizing from DatoCMS, so the `max-width: 100%` and `height: auto` rules are required to keep SVGs from overflowing their container. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add tests for the unhappy flows around the ::after pseudo: - the --unavailable-message CSS var must be a quoted CSS string literal, otherwise `content: var(...)` is invalid and the broken image styling never renders - the alt attribute falls back to an empty string when the image alt is missing Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace physical properties with their logical equivalents so the styling adapts to non-horizontal writing modes: - max-width / width / height -> max-inline-size / inline-size / block-size - top / left -> inset-block-start / inset-inline-start - padding-top -> padding-block-start Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Inline the props literal (typing it as a variable triggered a `Props & Props` intersection conflict against the renderer's generic) and narrow the figure query to `HTMLElement` so `style` is available. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`alt: null as unknown as string` lied about the type. The intent is "CMS did not send an alt" - express that by omitting the prop and annotating the missing required field with @ts-expect-error. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
95e7997 to
e9ff4dd
Compare
Changes
Associated issue
Resolves #356
How to test
Test broken image
ImgfilterBlock requests-> ClickBlock request URL.Checklist