--- import { Picture } from 'astro:assets'; import type { CollectionEntry } from 'astro:content'; import { absoluteUrl } from '../lib/site'; interface Props { post: CollectionEntry<'posts'>; } const { post } = Astro.props; const demoLink = post.data.links.find( (link) => !link.download && link.label.trim().toLowerCase() === 'demo' ); const iframeUrl = post.data.iframeThumbnail ? demoLink?.url : undefined; const iframeSrc = iframeUrl?.startsWith('/') ? absoluteUrl(iframeUrl) : iframeUrl; const iframeTitle = demoLink ? `${demoLink.label}: ${post.data.title}` : `Embedded demo: ${post.data.title}`; const aspectRatio = `${post.data.thumbnail.src.width} / ${post.data.thumbnail.src.height}`; const iframeThumbnailScript = ` for (const root of document.querySelectorAll('.post-thumbnail--iframe')) { const trigger = root.querySelector('[data-thumbnail-iframe-trigger]'); const frame = root.querySelector('[data-thumbnail-iframe-frame]'); if (!(trigger instanceof HTMLButtonElement) || !(frame instanceof HTMLIFrameElement)) { continue; } trigger.addEventListener( 'click', () => { const src = trigger.dataset.iframeSrc; if (!src) return; if (window.isSecureContext === false) { const opened = window.open('', '_blank'); if (!opened) { window.location.href = src; } else { opened.opener = null; opened.location.href = src; } return; } frame.src = src; frame.hidden = false; root.classList.add('is-active'); trigger.setAttribute('aria-expanded', 'true'); frame.focus(); }, { once: true } ); } `; ---