-
Notifications
You must be signed in to change notification settings - Fork 0
Utils
This is where a lot of the tricky logic of this small but dense component takes place. All of these functions are called in both the <Image />
and <AmpImage />
components.
Takes in all the properties from the <Image />
or <AmpImage />
that called it, expecting some mix of the image
, aspectRatio
and fallbackSrcSet
props in particular.
It figures out what aspect ratio it should use based on what is being asked for and if that aspect ratio exists, then it either generates the correct srcset string based on that information or returns the fallbackSrcSet
if it was provided. Returns null
if one truly cannot be found or created.
Takes in all the properties from the <Image />
or <AmpImage />
that called it, expecting some mix of the image
and aspectRatio
props.
It figures out what aspect ratio it should use based on what is being asked for and if that aspect ratio exists, then it either returns that array of image instances or returns the instances from the image.preferredAspectRatio
. Returns an empty array if one truly cannot be found or created.
Takes in all the properties from the <Image />
or <AmpImage />
that called it, expecting some mix of the image
and fallbackSrc
props. Returns image.fallback
property if available and the fallbackSrc
if not.
Takes in all the properties from the <Image />
or <AmpImage />
that called it, expecting some mix of the image
and alt
props. Returns in order of preference alt
, image.short_caption
and an empty string.
These functions are used by the above functions.
Takes in all the properties from the function that called it and makes use of aspectRatio
and image
. Figures out which aspect ratio to request in the following order of preference: aspectRatio
, image.preferredAspectRatio
, image.preferred_aspect_ratio_slug
, and uncropped
.
Takes in an array of image instances for a given aspectRatio and generates a valid srcset string.