Last active
August 29, 2015 14:01
-
-
Save dominikwilkowski/3fb9af0b929741a98772 to your computer and use it in GitHub Desktop.
Get first image from content
This file contains hidden or 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
{% comment %} | |
This snippet gets the first image from the parameter text | |
Usage: | |
{% include 'get-image' with page.content %} | |
Return: | |
{{ imageSrc }} is the string of the original image | |
Required: | |
String must be given in the parameter | |
{% endcomment %} | |
{% if get-image | size > 0 %} | |
{% assign content = get-image | split: 'src="' %} | |
{% assign imageSrc = content[1] | |
| split: '"' | |
| first | |
| replace: '//cdn', 'http://cdn' | |
| replace: 'http:http://', 'http://' | |
| remove: 'https:' | |
| remove: '_pico' | |
| remove: '_icon' | |
| remove: '_thumb' | |
| remove: '_small' | |
| remove: '_compact' | |
| remove: '_medium' | |
| remove: '_large' | |
| remove: '_grande' | |
| remove: '_1024x1024' | |
| remove: '_2048x2048' | |
%} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment