Skip to content

Commit

Permalink
Switch to uing <picture> for responsive images
Browse files Browse the repository at this point in the history
  • Loading branch information
alshedivat committed Nov 26, 2021
1 parent d574787 commit 1e4e147
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ jekyll-diagrams:
# configuration, see https://github.com/zhustec/jekyll-diagrams.
# feel free to comment out this section if not using jekyll diagrams.


# -----------------------------------------------------------------------------
# Optional Features
# -----------------------------------------------------------------------------
Expand All @@ -249,6 +250,7 @@ enable_project_categories: true # enables categorization of projects into
# multiple categories
enable_medium_zoom: true # enables image zoom feature (as on medium.com)


# -----------------------------------------------------------------------------
# Library versions
# -----------------------------------------------------------------------------
Expand Down
14 changes: 6 additions & 8 deletions _includes/responsive_img.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{% assign largest = resized | sort: 'width' | last %}
{% capture srcset %}
{% for i in resized %}
{{ i.path | relative_url }} {{ i.width }}w,
{% endfor %}
{% endcapture %}

<img {% if class %}class="{{ class }}"{% endif %} src="{{ largest.path | relative_url }}" srcset="{{ srcset | strip_newlines }} {{ path | relative_url }} {{ original.width }}w" {% if alt %}alt="{{ alt }}"{% endif %} {% if title %}title="{{ title }}"{% endif %} {% if zoomable %}data-zoomable{% endif %}/>
<picture>
{% for i in resized %}
<source media="(max-width: {{ i.width }}px)" srcset="{{ i.path | relative_url }}">
{% endfor %}
<img {% if class %}class="{{ class }}"{% endif %} src="{{ path | relative_url }}" {% if alt %}alt="{{ alt }}"{% endif %} {% if title %}title="{{ title }}"{% endif %} {% if zoomable %}data-zoomable{% endif %} />
</picture>

0 comments on commit 1e4e147

Please sign in to comment.