Skip to content

Instantly share code, notes, and snippets.

@opattison
Last active April 25, 2016 20:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opattison/21a69fc4265df0d5e739 to your computer and use it in GitHub Desktop.
Save opattison/21a69fc4265df0d5e739 to your computer and use it in GitHub Desktop.
Jekyll srcset imgix implementation with include file, srcset/sizes in config, YAML-provided images, and temporarily assigned variables
title image
example srcset implementation
src alt
/images/example.jpg
Don’t forget alt text.

{% assign image = page.image[0] %} {% include srcset.html %}

sizes: '(min-width: 70em) 1000px, (min-width: 50em) 750px, (min-width: 40em) 500px, 100vw'
srcset:
- 500
- 750
- 1000
<img
src="{{ image.src }}"
sizes="{{ site.sizes }}"
srcset="{% for width in site.srcset %}{{ width}}/{{ image.src }} {{ width }}w{% if forloop.last == false %}, {% endif %}{% endfor %}"
alt="{{ image.alt }}">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment