(() => { document.addEventListener("DOMContentLoaded", init); async function init() { document.getElementById("currentYear").textContent = new Date().getFullYear(); await loadArtists(); } async function loadArtists() { const loadingEl = document.getElementById("loading"); const errorEl = document.getElementById("error"); const gridEl = document.getElementById("artistGrid"); errorEl.style.display = "none"; loadingEl.style.display = "block"; try { const url = `./data/artists.json?v=${Date.now()}`; const res = await fetch(url, { cache: "no-store", headers: { "Accept": "application/json" } }); if (!res.ok) { throw new Error(`artists.json fetch failed: ${res.status} ${res.statusText}`); } const artists = await res.json(); loadingEl.style.display = "none"; if (!Array.isArray(artists) || artists.length === 0) { gridEl.innerHTML = '
Keine Künstler-Daten verfügbar.
'; return; } const frag = document.createDocumentFragment(); for (const artist of artists) { frag.appendChild(createArtistCardNode(artist)); } gridEl.replaceChildren(frag); } catch (err) { console.error("Error loading artists:", err); loadingEl.style.display = "none"; errorEl.style.display = "block"; gridEl.textContent = ""; } } function createArtistCardNode(artist) { const article = document.createElement("article"); article.className = "artist-card"; const inner = document.createElement("div"); inner.className = "card-inner"; const imageContainer = document.createElement("div"); imageContainer.className = "image-container"; if (artist.orientation) { imageContainer.classList.add(artist.orientation); } const img = document.createElement("img"); img.className = "artist-image"; img.src = artist.image; img.alt = `${artist.role} von ${artist.name}`; img.loading = "lazy"; img.decoding = "async"; img.dataset.orientation = artist.orientation || 'auto'; imageContainer.appendChild(img); const content = document.createElement("div"); content.className = "content"; const name = document.createElement("h2"); name.className = "artist-name"; name.textContent = artist.name; const role = document.createElement("div"); role.className = "artist-role"; role.textContent = artist.role; const desc = document.createElement("p"); desc.className = "artist-description"; desc.textContent = artist.description ?? ""; content.appendChild(name); content.appendChild(role); content.appendChild(desc); const links = createSocialLinksNode(artist.links); if (links) content.appendChild(links); inner.appendChild(imageContainer); inner.appendChild(content); article.appendChild(inner); return article; } function createSocialLinksNode(links) { if (!links) return null; const wrap = document.createElement("div"); wrap.className = "social-links"; const order = ["vgen", "twitter", "bluesky", "youtube", "twitch", "instagram", "fiverr", "website"]; for (const platform of order) { if (!links[platform]) continue; wrap.appendChild(createIconLink(platform, links[platform])); } return wrap.childElementCount ? wrap : null; } function createIconLink(platform, url) { const a = document.createElement("a"); a.href = url; a.className = `social-link ${platform}`; a.target = "_blank"; a.rel = "noopener"; a.ariaLabel = platform; a.innerHTML = getPlatformSvg(platform); return a; } function getPlatformSvg(platform) { const svgs = { vgen: ``, twitter: ``, bluesky: ``, youtube: ``, twitch: ``, instagram: ``, fiverr: ``, website: `` } return svgs[platform] || ""; } })();