Skip to content

Commit

Permalink
feat(amsf): a simpler and more reliable way to get first image
Browse files Browse the repository at this point in the history
  • Loading branch information
sparanoid committed Nov 28, 2016
1 parent c3c8591 commit 5c131b2
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions _app/_includes/_amsf.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,13 @@

{% comment %}
Page thumbnail
TODO: https://regex101.com/r/N2hoxV/1
{% endcomment %}
{% capture amsf_post_first_image %}
{% assign post_images = page.content | split: "<img " %}
{% assign hero_image = '/logo.png' | prepend: amsf_site_base %}
{% for image in post_images %}
{% if image contains "src=" %}
{% assign hero_image = image | split: ">" | first | match_regex: 'src="([^"]+)"' %}
{% break %}
{% endif %}
{% endfor %}
{% assign hero_image = page.content | match_regex: '<img .*?src="([^"]+)"' %}
{% if hero_image == nil %}
{% assign hero_image = "/logo.png" | prepend: amsf_site_base %}
{% endif %}
{{ hero_image }}
{% endcapture %}

Expand Down

0 comments on commit 5c131b2

Please sign in to comment.