Skip to content

Commit cc20b04

Browse files
authored
Enhance news card rendering with dynamic thumbnails
1 parent 0008870 commit cc20b04

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

‎index.html‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,43 @@ <h1 class="hero-title">DEVLAB<br>STUDY<span>_</span></h1>
391391
<div class="newsy-home-grid">
392392
{% for post in site.newsy limit:3 %}
393393
<a href="{{ post.url | relative_url }}" class="home-news-card">
394-
{% include news-thumb.html post=post %}
394+
{% assign t = post %}
395+
{% assign thumb = t.icon | default: t.image %}
396+
{% assign is_icon = false %}
397+
{% if t.icon %}{% assign is_icon = true %}{% endif %}
398+
399+
{% if thumb == blank %}
400+
{% if t.content contains '<img' %}
401+
{% assign thumb = t.content | split: '<img' | second | split: 'src="' | second | split: '"' | first %}
402+
{% elsif t.content contains '![' %}
403+
{% assign thumb = t.content | split: '![' | second | split: '](' | second | split: ')' | first %}
404+
{% endif %}
405+
{% endif %}
406+
407+
{% assign cat = t.category | default: "brief" | downcase %}
408+
{% case cat %}
409+
{% when "hardware" %}{% assign emoji = "💻" %}
410+
{% when "homelab" %}{% assign emoji = "🗄️" %}
411+
{% when "mikrotik", "sieć", "siec", "network" %}{% assign emoji = "🌐" %}
412+
{% when "proxmox" %}{% assign emoji = "🖥️" %}
413+
{% when "cisco" %}{% assign emoji = "🔌" %}
414+
{% else %}{% assign emoji = "⚡" %}
415+
{% endcase %}
416+
417+
<div class="news-thumb">
418+
{% if thumb != blank %}
419+
{% assign thumb_src = thumb %}
420+
{% unless thumb contains '://' %}
421+
{% assign thumb_src = thumb | relative_url %}
422+
{% endunless %}
423+
<img src="{{ thumb_src }}" alt="" loading="lazy"
424+
class="news-thumb-img {% if is_icon %}is-icon{% endif %}"
425+
onerror="this.style.display='none'; this.nextElementSibling.style.display='flex';">
426+
<span class="news-thumb-fallback" style="display:none">{{ emoji }}</span>
427+
{% else %}
428+
<span class="news-thumb-fallback">{{ emoji }}</span>
429+
{% endif %}
430+
</div>
395431
<div class="home-news-content">
396432
<div>
397433
<div style="font-family: 'JetBrains Mono', monospace; font-size: 0.75rem; color: var(--accent-contrast); margin-bottom: 8px; font-weight: 800;">

0 commit comments

Comments
 (0)