Created
October 19, 2014 21:09
-
-
Save darryn/3ff0e11fa3d68ed35ed1 to your computer and use it in GitHub Desktop.
Shopify - Strip image out of blog article excerpt
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
{% assign sizes = '_pico.,_icon.,_thumb.,_small.,_compact.,_medium.,_large.,_grande.,_1024x1024.,_2048x2048.,_master' | split: ',' %} | |
{% assign default_image = 'filename.jpg] %} | |
{% for a in blog.articles %} | |
{% assign src = null %} | |
{% if excerpt contains "<img" %} | |
{% assign src = excerpt | split: 'src="' %} | |
{% assign src = src[1] | split: '"' | first | replace: '//cdn', 'http://cdn'; | replace: 'http:http://';, 'http://'; | remove: 'https:' %} | |
{% for s in sizes %} | |
{% assign src = src | replace: s, '_large.' %} | |
{% endfor %} | |
{% endif %} | |
<article> | |
<header> | |
<h3>{{ a.title | link_to: a.url }}</h3> | |
</header> | |
<section> | |
<a href="{{ a.url }}" title="View {{ a.title }}"> | |
{% if src != null %} | |
<img src="{{ src }}" alt="{{ a.title }}> | |
{% else %} | |
<img src="{{ default_image | asset_url }}" alt="{{ a.title }}> | |
{% endif %} | |
</a> | |
<p>{{ a.content | strip_html | truncatewords: 50 }}</p> | |
</section | |
</article> | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment