-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
36 lines (31 loc) · 1.14 KB
/
Copy pathmain.js
File metadata and controls
36 lines (31 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export function renderSocialLinks(socials, container, documentRoot = document) {
const links = socials.map(({ name, url, icon }) => {
const link = documentRoot.createElement("a");
link.className = "social-link";
link.href = url;
link.target = "_blank";
link.rel = "noopener noreferrer";
link.setAttribute("aria-label", name);
const image = documentRoot.createElement("img");
image.src = icon;
image.alt = "";
link.append(image);
return link;
});
container.replaceChildren(...links);
}
async function loadSocialLinks() {
const container = document.getElementById("social-links");
try {
const response = await fetch("./socials.json");
if (!response.ok) throw new Error(`Social links request failed: ${response.status}`);
renderSocialLinks(await response.json(), container);
} catch (error) {
console.error(error);
container.textContent = "Social links are unavailable right now.";
}
}
if (typeof document !== "undefined") {
loadSocialLinks();
document.getElementById("fader").classList.add("fade-out");
}