Skip to content

Commit 23ea2f4

Browse files
committed
feat: add loader with spinner on index.html to handle delay
closes #7
1 parent f1623dd commit 23ea2f4

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

assets/index.html

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Waiting for GitHub Pages Deployment</title>
6+
<style>
7+
@import url('nord.css');
8+
body {
9+
height: 100vh;
10+
margin: 0;
11+
display: flex;
12+
flex-direction: column;
13+
align-items: center;
14+
justify-content: center;
15+
gap: 10px;
16+
}
17+
#spinner {
18+
display: none;
19+
border: 4px solid var(--nord1);
20+
border-top: 4px solid var(--nord3);
21+
border-radius: 50%;
22+
width: 25px;
23+
height: 25px;
24+
animation: spin 2s linear infinite;
25+
}
26+
p {
27+
font-size: 12px;
28+
}
29+
@keyframes spin {
30+
0% { transform: rotate(0deg); }
31+
100% { transform: rotate(360deg); }
32+
}
33+
</style>
34+
<script>
35+
function getHashFromQueryString() {
36+
const params = new URLSearchParams(window.location.search);
37+
return params.get("hash");
38+
}
39+
40+
async function checkFileExists(url) {
41+
try {
42+
const response = await fetch(url, { method: "HEAD" });
43+
return response.ok;
44+
} catch (error) {
45+
return false;
46+
}
47+
}
48+
49+
async function waitForFileToExist(url, interval = 2000) {
50+
while (true) {
51+
if (await checkFileExists(url)) {
52+
return true;
53+
}
54+
await new Promise((resolve) => setTimeout(resolve, interval));
55+
}
56+
}
57+
58+
async function loadContent() {
59+
const spinner = document.getElementById("spinner");
60+
const hash = getHashFromQueryString();
61+
const fileUrl = `${hash}.html`;
62+
63+
spinner.style.display = "block";
64+
65+
await waitForFileToExist(fileUrl);
66+
67+
window.location.href = fileUrl;
68+
}
69+
70+
document.addEventListener("DOMContentLoaded", loadContent);
71+
72+
</script>
73+
</head>
74+
<body>
75+
<div id="spinner"></div>
76+
<p>Waiting for GitHub Pages Deployment</p>
77+
</body>
78+
</html>

src/update-comment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const updateCodeCoverageComment = module.exports = async ({ context, github }, r
1414

1515
const commentBody = [
1616
'<!-- coverage -->',
17-
`### [Code Coverage Report 🔗](https://${context.repo.owner}.github.io/${context.repo.repo}/${revision}.html#file0) for ${revision}`,
17+
`### [Code Coverage Report 🔗](https://${context.repo.owner}.github.io/${context.repo.repo}/?hash=${revision}) for ${revision}`,
1818
]
1919

2020
if (fs.existsSync('cover.txt') === true) {

0 commit comments

Comments
 (0)