Skip to content

Instantly share code, notes, and snippets.

@dominikwilkowski
Last active August 29, 2015 14:01
Show Gist options
  • Save dominikwilkowski/3fb9af0b929741a98772 to your computer and use it in GitHub Desktop.
Save dominikwilkowski/3fb9af0b929741a98772 to your computer and use it in GitHub Desktop.
Get first image from content
{% 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