Last active
March 22, 2017 16:03
-
-
Save mwickett/4373521a5deaa1a84a0dd881afbae073 to your computer and use it in GitHub Desktop.
SugarML responsive image snippet (Atom)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'.source.sugarml': | |
'Responsive Imaage': | |
'prefix': 'rimg' | |
'body': """ | |
picture | |
source(type='image/webp' | |
srcset='{{ $1 }}?fm=webp&w=2000&fit=fill 2000w, | |
{{ $1 }}?fm=webp&w=1500&fit=fill 1500w, | |
{{ $1 }}?fm=webp&w=900 900w, | |
{{ $1 }}?fm=webp&w=450 450w') | |
img(src='{{ $1 }}?fm=jpg&w=900&fit=fill' | |
srcset='{{ $1 }}?fm=jpg&w=2000&fit=fill 2000w, | |
{{ $1 }}?fm=jpg&w=1500&fit=fill 1500w, | |
{{ $1 }}?fm=jpg&w=900 900w, | |
{{ $1 }}?fm=jpg&w=450 450w' | |
alt='{{ $2 }}') | |
""" |
Improved with line breaks for better readability. It's a chunker!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added
&fit=fill
so that Contentful will always deliver an image. If you ask for a larger resolution that the original size, without specifyingfill
, then it returns 404, which is not ideal. Warning:fit=fill
will result in upscaling in cases where the image is smaller, so can mean poor quality.