-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (42 loc) · 1.61 KB
/
Copy pathscript.js
File metadata and controls
48 lines (42 loc) · 1.61 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
37
38
39
40
41
42
43
44
45
46
47
48
const repo = "Samielakkad/darija-tools";
const apiUrl = `https://api.github.com/repos/${repo}`;
const fields = {
description: document.querySelector("#description"),
stars: document.querySelector("#stars"),
forks: document.querySelector("#forks"),
issues: document.querySelector("#issues"),
language: document.querySelector("#language"),
updated: document.querySelector("#updated"),
repoLink: document.querySelector("#repo-link"),
};
const formatNumber = new Intl.NumberFormat("en");
const formatDate = new Intl.DateTimeFormat("en", {
dateStyle: "medium",
timeStyle: "short",
});
async function loadRepo() {
try {
const response = await fetch(apiUrl, {
headers: {
Accept: "application/vnd.github+json",
},
});
if (!response.ok) {
throw new Error(`GitHub API returned ${response.status}`);
}
const data = await response.json();
fields.description.textContent =
data.description || "Moroccan Darija normalization and transliteration tools.";
fields.stars.textContent = formatNumber.format(data.stargazers_count);
fields.forks.textContent = formatNumber.format(data.forks_count);
fields.issues.textContent = formatNumber.format(data.open_issues_count);
fields.language.textContent = data.language || "n/a";
fields.updated.textContent = `Last pushed ${formatDate.format(new Date(data.pushed_at))}`;
fields.repoLink.href = data.html_url;
} catch (error) {
fields.description.textContent =
"Could not load the live GitHub API data. The repository link still works.";
fields.updated.textContent = error.message;
}
}
loadRepo();