Skip to content

Commit 7e5a42f

Browse files
authored
Extract image source from post content for thumbnails
1 parent cdeb092 commit 7e5a42f

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

‎newsy.html‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,20 @@ <h1>Tech Briefs & News</h1>
260260

261261
<div class="newsy-grid" id="newsGrid">
262262
{% for post in site.newsy %}
263-
{% assign post_thumb = post.image %}
263+
<!-- Automatyczne wyciąganie pierwszego obrazka z treści posta -->
264+
{% assign post_thumb = nil %}
265+
{% if post.content contains '<img' %}
266+
{% assign img_tag = post.content | split: '<img' | second %}
267+
{% assign img_src = img_tag | split: 'src="' | second | split: '"' | first %}
268+
{% if img_src %}
269+
{% assign post_thumb = img_src %}
270+
{% endif %}
271+
{% endif %}
264272
{% unless post_thumb %}
265-
{% if post.content contains '<img' %}
266-
{% assign img_tag = post.content | split: '<img' | second %}
267-
{% assign img_src = img_tag | split: 'src="' | second | split: '"' | first %}
268-
{% if img_src %}
269-
{% assign post_thumb = img_src %}
273+
{% if post.content contains '![' %}
274+
{% assign md_img = post.content | split: '![' | second | split: ']' | second | split: '(' | second | split: ')' | first %}
275+
{% if md_img %}
276+
{% assign post_thumb = md_img %}
270277
{% endif %}
271278
{% endif %}
272279
{% endunless %}
@@ -276,7 +283,7 @@ <h1>Tech Briefs & News</h1>
276283
<a href="{{ post.url }}" class="news-card" data-title="{{ post.title | downcase }}" data-category="{{ post_cat }}">
277284
<div style="display: flex; flex-direction: column; height: 100%;">
278285
{% if post_thumb %}
279-
<img src="{{ post_thumb }}" alt="{{ post.title }}" class="news-card-thumb">
286+
<img src="{{ post_thumb | relative_url }}" alt="{{ post.title }}" class="news-card-thumb">
280287
{% endif %}
281288
<div class="news-card-content">
282289
<div>

0 commit comments

Comments
 (0)