{% assign preview_img = page.preview.image %}
{% assign preview_src = preview_img.path | default: preview_img | append: '' %}
{%- comment -%} `image` may be a mapping ({ path: …, … }) or a bare string
(image: /x.png). A mapping without a `path` (e.g. only default style keys, or
a video-only preview) stringifies to a Ruby hash dump containing "=>", which
would leak into the tag as broken markup — so treat that (and an empty
value) as "no image". {%- endcomment -%}
{% if preview_src != '' and preview_src != empty %}{% unless preview_src contains '=>' %}
{% capture img_style %}
{% if preview_img.aspect_ratio %}--preview-aspect-ratio: {{ preview_img.aspect_ratio }};{% endif %}
{% if preview_img.object_fit %}--preview-object-fit: {{ preview_img.object_fit }};{% endif %}
{% if preview_img.max_width %}--preview-max-width: {{ preview_img.max_width }};{% endif %}
{% endcapture %}
{% assign img_style_stripped = img_style | strip %}
{% capture style %}{% if img_style_stripped != '' %}style="{{ img_style_stripped }}"{% endif %}{% endcapture %}
{% capture src %}src="{{ preview_src }}"{% endcapture %}
{% capture class %}class="preview-img{% if preview_img.no_bg %}{{ ' no-bg' }}{% endif %}"{% endcapture %}
{% capture alt %}alt="{{ page.preview.alt | default: "Preview Image" }}"{% endcapture %}
{% capture lqip %}
{% if preview_img.lqip %}
lqip="{{ preview_img.lqip }}"
{% endif %}
{% endcapture %}