Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.