diff --git a/assets/js/main.js b/assets/js/main.js index f2c4c75..f65e304 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -187,6 +187,33 @@ const paperDiv = document.createElement("div"); paperDiv.className = "featured-paper"; paperDiv.style.cursor = "pointer"; + let sectionHasStaticImage = false; + + const hasNonBadgeImage = (element) => { + const images = element.matches("img") + ? [element] + : Array.from(element.querySelectorAll("img")); + + return images.some((image) => { + const src = image.getAttribute("src") || ""; + return !src.includes("img.shields.io"); + }); + }; + + for ( + let cursor = section.nextElementSibling; + cursor; + cursor = cursor.nextElementSibling + ) { + if (cursor.matches("h3")) { + break; + } + + if (hasNonBadgeImage(cursor)) { + sectionHasStaticImage = true; + break; + } + } // Get all content until the next h3 or end let content = [section.cloneNode(true)]; @@ -223,8 +250,14 @@ continue; } - // Keep homepage cards lightweight: skip embedded media. + // Skip embedded media when the paper already has a static image. + // Otherwise keep the iframe so cards do not lose their only media. if (nextEl.matches("iframe")) { + if (!sectionHasStaticImage) { + const iframeClone = nextEl.cloneNode(true); + iframeClone.setAttribute("loading", "lazy"); + content.push(iframeClone); + } nextEl = nextEl.nextElementSibling; continue; } diff --git a/tests/featured-papers-regression.test.js b/tests/featured-papers-regression.test.js new file mode 100644 index 0000000..a2f2655 --- /dev/null +++ b/tests/featured-papers-regression.test.js @@ -0,0 +1,72 @@ +describe("featured papers homepage media handling", () => { + const researchHtml = ` +
