Skip to content

Commit 2e196ac

Browse files
committed
fix(site): show only Wikimedia Commons photos, credited to their file page
Device cards rendered any image_url, which put hotlinked third-party product photos on the public site. Render only upload.wikimedia.org/wikipedia/commons files, and add a 'Photo: Wikimedia Commons' credit linking to the file page, which lists the author and license (CC BY-SA allows attribution by link). Refs #19
1 parent 2f939de commit 2e196ac

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎site/src/scripts/techapi.js‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,11 @@ const CARD = {
702702
const prettyBench = (s) => s ? s.replace(/_/g, " ").replace(/\b(cpu|gpu|g3d|fp32|r23|r15|r10|r11 5|2024)\b/gi,
703703
(m) => m.toUpperCase()).replace(/\bcinebench\b/i, "Cinebench").replace(/\bgeekbench\b/i, "Geekbench")
704704
.replace(/\bpassmark\b/i, "PassMark").replace(/\bantutu score\b/i, "AnTuTu").replace(/\btimespy\b/i, "Time Spy") : "";
705+
// Only free-licensed Wikimedia Commons photos are shown; their file page carries the author and license.
706+
const commonsPage = (url) => {
707+
const m = /^https:\/\/upload\.wikimedia\.org\/wikipedia\/commons\/(?:thumb\/)?[0-9a-f]\/[0-9a-f]{2}\/([^/?#]+)/.exec(url || "");
708+
return m ? `https://commons.wikimedia.org/wiki/File:${m[1]}` : null;
709+
};
705710

706711
function deviceCard(d, category = "smartphones") {
707712
const cfg = CARD[category] || CARD.smartphones;
@@ -728,10 +733,18 @@ function deviceCard(d, category = "smartphones") {
728733
</div>
729734
<div class="chips">${tier}${era}${specs.map((s) => `<span class="chip">${esc(s)}</span>`).join("")}</div>
730735
<div class="bars">${cfg.bars(sc).map(([l, v]) => bar(l, v)).join("")}</div>${src}`;
731-
if (d.image_url) {
736+
const photoPage = commonsPage(d.image_url);
737+
if (photoPage) {
732738
const img = new Image();
733739
img.src = d.image_url; img.alt = d.name; img.loading = "lazy"; img.className = "thumb-img";
734-
img.onload = () => el.querySelector(".thumb").appendChild(img);
740+
img.onload = () => {
741+
el.querySelector(".thumb").appendChild(img);
742+
const credit = document.createElement("div");
743+
credit.className = "card-src";
744+
credit.innerHTML = `<a href="${esc(photoPage)}" target="_blank" rel="noopener">Photo: Wikimedia Commons</a>`;
745+
credit.firstChild.addEventListener("click", (e) => e.stopPropagation());
746+
el.appendChild(credit);
747+
};
735748
}
736749
el.addEventListener("click", () => {
737750
resSel.value = category; slugIn.value = d.slug; run(category, d.slug);

0 commit comments

Comments
 (0)