Skip to content

Commit 8cf8d6f

Browse files
committed
update: Updates files
1 parent d32abb1 commit 8cf8d6f

File tree

8 files changed

+428
-12
lines changed

8 files changed

+428
-12
lines changed

site/404.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Redirecting... | Testify</title>
7+
<script>
8+
// This script helps handle GitHub Pages routing
9+
(function() {
10+
// Split the URL path
11+
const path = window.location.pathname;
12+
const search = window.location.search;
13+
14+
// Store the URL for redirecting
15+
sessionStorage.setItem('redirect', path + search);
16+
17+
// Redirect to index page which will handle the routing
18+
window.location.href = '/index.html';
19+
})();
20+
</script>
21+
<style>
22+
body {
23+
font-family: 'Satoshi', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
24+
background-color: #121212;
25+
color: #e0e0e0;
26+
display: flex;
27+
align-items: center;
28+
justify-content: center;
29+
height: 100vh;
30+
margin: 0;
31+
flex-direction: column;
32+
text-align: center;
33+
}
34+
.loader {
35+
border: 5px solid rgba(255, 255, 255, 0.1);
36+
border-radius: 50%;
37+
border-top: 5px solid #8a2be2;
38+
width: 50px;
39+
height: 50px;
40+
animation: spin 1s linear infinite;
41+
margin-bottom: 20px;
42+
}
43+
@keyframes spin {
44+
0% { transform: rotate(0deg); }
45+
100% { transform: rotate(360deg); }
46+
}
47+
h2 {
48+
font-size: 24px;
49+
margin-bottom: 10px;
50+
}
51+
p {
52+
font-size: 16px;
53+
color: #a0a0a0;
54+
}
55+
</style>
56+
</head>
57+
<body>
58+
<div class="loader"></div>
59+
<h2>Redirecting you...</h2>
60+
<p>Please wait while we take you to the right page.</p>
61+
</body>
62+
</html>

site/index.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,36 @@
3030
},
3131
};
3232
</script>
33+
<script>
34+
// GitHub Pages route handling
35+
document.addEventListener('DOMContentLoaded', function() {
36+
// Check if we have a redirect saved in session storage (from 404.html)
37+
const redirect = sessionStorage.getItem('redirect');
38+
if (redirect) {
39+
// Clear the redirect from session storage
40+
sessionStorage.removeItem('redirect');
41+
42+
// Parse the saved URL path
43+
const path = redirect.split('?')[0];
44+
45+
// Handle leaderboard routes
46+
if (path.includes('/leaderboard/')) {
47+
const pathParts = path.split('/');
48+
const lastPart = pathParts[pathParts.length - 1];
49+
50+
if (lastPart === 'global') {
51+
window.location.href = './global-leaderboard.html';
52+
return;
53+
} else if (lastPart && lastPart !== 'leaderboard') {
54+
// Store guild ID and redirect to leaderboard page
55+
sessionStorage.setItem('guildId', lastPart);
56+
window.location.href = './leaderboard.html';
57+
return;
58+
}
59+
}
60+
}
61+
});
62+
</script>
3363
<style>
3464
.sidebar-link {
3565
pointer-events: auto !important;
@@ -1122,5 +1152,6 @@ <h4 class="text-lg font-bold mb-4 text-white">Connect</h4>
11221152
</footer>
11231153

11241154
<script src="./js/main.js"></script>
1155+
<script src="./js/api-config.js"></script>
11251156
</body>
11261157
</html>

site/js/api-config.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// API Configuration for Testify Leaderboard
2+
const API_CONFIG = {
3+
// Main API endpoint - change this for production
4+
BASE_URL: window.location.hostname.includes('github.io') ||
5+
window.location.hostname.includes('testify.lol')
6+
? 'https://api.testify.lol' : '',
7+
8+
// For GitHub Pages, we'll use mock data
9+
USE_MOCK_DATA: window.location.hostname.includes('github.io') ||
10+
window.location.hostname.includes('testify.lol'),
11+
12+
// API endpoints
13+
ENDPOINTS: {
14+
GUILD_LEADERBOARD: '/api/leaderboard/{guildId}',
15+
GLOBAL_LEADERBOARD: '/api/leaderboard/global',
16+
USER_INFO: '/api/user/{userId}',
17+
GUILD_INFO: '/api/guild/{guildId}'
18+
},
19+
20+
// Mock data paths (for GitHub Pages)
21+
MOCK_DATA: {
22+
GUILD_LEADERBOARD: '/mock-data/leaderboard-example.json',
23+
GLOBAL_LEADERBOARD: '/mock-data/global-leaderboard-example.json'
24+
},
25+
26+
// Get the appropriate API URL based on environment
27+
getApiUrl: function(endpoint, params = {}) {
28+
let url = this.USE_MOCK_DATA ? this.getMockUrl(endpoint) : this.BASE_URL + endpoint;
29+
30+
// Replace any parameters in the URL
31+
for (const [key, value] of Object.entries(params)) {
32+
url = url.replace(`{${key}}`, value);
33+
}
34+
35+
return url;
36+
},
37+
38+
// Get mock data URL for GitHub Pages
39+
getMockUrl: function(endpoint) {
40+
if (endpoint.startsWith(this.ENDPOINTS.GUILD_LEADERBOARD.split('{')[0])) {
41+
return this.MOCK_DATA.GUILD_LEADERBOARD;
42+
} else if (endpoint === this.ENDPOINTS.GLOBAL_LEADERBOARD) {
43+
return this.MOCK_DATA.GLOBAL_LEADERBOARD;
44+
}
45+
46+
return this.BASE_URL + endpoint;
47+
}
48+
};

site/js/global-leaderboard.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,27 @@ document.addEventListener('DOMContentLoaded', function() {
4343
}
4444
});
4545

46+
// API endpoint handling for GitHub Pages
47+
function getApiEndpoint(endpoint) {
48+
// Check if running on GitHub Pages
49+
const isGitHubPages = window.location.hostname.includes('github.io') ||
50+
window.location.hostname.includes('testify.lol');
51+
52+
if (isGitHubPages) {
53+
// For GitHub Pages, use the mock data endpoint
54+
return `https://api.testify.lol${endpoint}`;
55+
} else {
56+
// For local development
57+
return endpoint;
58+
}
59+
}
60+
4661
// Functions
4762
async function fetchGlobalLeaderboard(page) {
4863
try {
49-
const response = await fetch(`/api/leaderboard/global?page=${page}`);
64+
const apiUrl = getApiEndpoint(`/api/leaderboard/global?page=${page}`);
65+
66+
const response = await fetch(apiUrl);
5067

5168
if (!response.ok) {
5269
throw new Error(`Server returned ${response.status}: ${response.statusText}`);
@@ -83,15 +100,15 @@ document.addEventListener('DOMContentLoaded', function() {
83100
// Try to fetch user info from Discord API
84101
let userInfo;
85102
try {
86-
const userResponse = await fetch(`/api/user/${user._id}`);
103+
const userResponse = await fetch(getApiEndpoint(`/api/user/${user._id}`));
87104
if (userResponse.ok) {
88105
userInfo = await userResponse.json();
89106
}
90107
} catch (e) {
91108
console.warn(`Could not fetch user info for ${user._id}:`, e);
92109
}
93110

94-
const userTag = userInfo?.tag || 'Unknown User';
111+
const userTag = userInfo?.tag || user._id || 'Unknown User';
95112
const avatarUrl = userInfo?.avatarURL || `https://cdn.discordapp.com/embed/avatars/${Math.floor(Math.random() * 5)}.png`;
96113
const guildCount = user.guilds ? user.guilds.length : 0;
97114

@@ -160,6 +177,6 @@ document.addEventListener('DOMContentLoaded', function() {
160177
}
161178

162179
function hideError() {
163-
errorContainer.classList.add('hidden');
180+
errorContainer.classList.remove('hidden');
164181
}
165182
});

site/js/leaderboard.js

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,28 @@ document.addEventListener('DOMContentLoaded', function() {
1919
let totalPages = 1;
2020
let guildId = '';
2121

22-
// Extract guild ID from URL
23-
const pathParts = window.location.pathname.split('/');
24-
guildId = pathParts[pathParts.length - 1];
22+
// Extract guild ID from URL or session storage (for GitHub Pages)
23+
const getGuildId = () => {
24+
// Check if running on GitHub Pages
25+
const isGitHubPages = window.location.hostname.includes('github.io') ||
26+
window.location.hostname.includes('testify.lol');
27+
28+
if (isGitHubPages) {
29+
// Get guild ID from session storage (set by the routing page)
30+
return sessionStorage.getItem('guildId');
31+
} else {
32+
// Standard path extraction for development environment
33+
const pathParts = window.location.pathname.split('/');
34+
return pathParts[pathParts.length - 1];
35+
}
36+
};
37+
38+
guildId = getGuildId();
39+
40+
if (!guildId) {
41+
showError("No guild ID found. Please go back and try again.");
42+
return;
43+
}
2544

2645
// Initialize
2746
fetchLeaderboard(currentPage);
@@ -52,13 +71,36 @@ document.addEventListener('DOMContentLoaded', function() {
5271
});
5372

5473
globalBtn.addEventListener('click', () => {
55-
window.location.href = '/leaderboard/global';
74+
// Handle GitHub Pages routing
75+
if (window.location.hostname.includes('github.io') ||
76+
window.location.hostname.includes('testify.lol')) {
77+
window.location.href = '/leaderboard/global';
78+
} else {
79+
window.location.href = '/leaderboard/global';
80+
}
5681
});
5782

83+
// API endpoint handling for GitHub Pages
84+
function getApiEndpoint(endpoint) {
85+
// Check if running on GitHub Pages
86+
const isGitHubPages = window.location.hostname.includes('github.io') ||
87+
window.location.hostname.includes('testify.lol');
88+
89+
if (isGitHubPages) {
90+
// For GitHub Pages, use the mock data endpoint
91+
return `https://api.testify.lol${endpoint}`;
92+
} else {
93+
// For local development
94+
return endpoint;
95+
}
96+
}
97+
5898
// Functions
5999
async function fetchLeaderboard(page) {
60100
try {
61-
const response = await fetch(`/api/leaderboard/${guildId}?page=${page}`);
101+
const apiUrl = getApiEndpoint(`/api/leaderboard/${guildId}?page=${page}`);
102+
103+
const response = await fetch(apiUrl);
62104

63105
if (!response.ok) {
64106
throw new Error(`Server returned ${response.status}: ${response.statusText}`);
@@ -76,11 +118,15 @@ document.addEventListener('DOMContentLoaded', function() {
76118
// Update guild info if available
77119
if (data.guildId) {
78120
try {
79-
const discordApiResponse = await fetch(`/api/guild/${data.guildId}`);
121+
const discordApiResponse = await fetch(getApiEndpoint(`/api/guild/${data.guildId}`));
80122
if (discordApiResponse.ok) {
81123
const guildData = await discordApiResponse.json();
82124
guildNameEl.textContent = guildData.name || 'Guild Leaderboard';
83125
guildInfoEl.textContent = `${guildData.memberCount || 'Unknown'} members`;
126+
} else {
127+
// Fallback if API call fails
128+
guildNameEl.textContent = 'Guild Leaderboard';
129+
guildInfoEl.textContent = `Guild ID: ${data.guildId}`;
84130
}
85131
} catch (e) {
86132
console.warn('Could not fetch guild details:', e);
@@ -111,15 +157,15 @@ document.addEventListener('DOMContentLoaded', function() {
111157
// Try to fetch user info from Discord API
112158
let userInfo;
113159
try {
114-
const userResponse = await fetch(`/api/user/${user.User}`);
160+
const userResponse = await fetch(getApiEndpoint(`/api/user/${user.User}`));
115161
if (userResponse.ok) {
116162
userInfo = await userResponse.json();
117163
}
118164
} catch (e) {
119165
console.warn(`Could not fetch user info for ${user.User}:`, e);
120166
}
121167

122-
const userTag = userInfo?.tag || 'Unknown User';
168+
const userTag = userInfo?.tag || user.User || 'Unknown User';
123169
const avatarUrl = userInfo?.avatarURL || `https://cdn.discordapp.com/embed/avatars/${Math.floor(Math.random() * 5)}.png`;
124170

125171
row.innerHTML = `

site/leaderboard/index.html

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<!DOCTYPE html>
2+
<html lang="en" class="dark-mode">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
6+
<title>Testify - Leaderboard Router</title>
7+
<script src="https://cdn.tailwindcss.com"></script>
8+
<link rel="stylesheet" href="../css/styles.css" />
9+
<link rel="stylesheet" href="../css/leaderboard.css" />
10+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
11+
<link rel="icon" type="image/png" href="https://i.postimg.cc/KznLsF43/Testi-1.png" />
12+
<script>
13+
tailwind.config = {
14+
darkMode: "class",
15+
theme: {
16+
extend: {
17+
colors: {
18+
primary: {
19+
DEFAULT: "#8a2be2",
20+
light: "#9932cc",
21+
dark: "#6a0dad",
22+
},
23+
dark: {
24+
DEFAULT: "#121212",
25+
gray: "#1e1e1e",
26+
light: "#333333",
27+
},
28+
},
29+
},
30+
},
31+
};
32+
33+
// Route handling for GitHub Pages
34+
document.addEventListener('DOMContentLoaded', function() {
35+
const path = window.location.pathname;
36+
const pathParts = path.split('/');
37+
38+
// Handle global leaderboard
39+
if (path.endsWith('/global')) {
40+
window.location.href = '../global-leaderboard.html';
41+
return;
42+
}
43+
44+
// Handle guild leaderboard
45+
const guildId = pathParts[pathParts.length - 1];
46+
if (guildId && guildId !== 'leaderboard' && !isNaN(guildId)) {
47+
// Store guild ID in session storage for the leaderboard page to use
48+
sessionStorage.setItem('guildId', guildId);
49+
window.location.href = '../leaderboard.html';
50+
return;
51+
}
52+
53+
// Default to home page if no valid route
54+
window.location.href = '../index.html';
55+
});
56+
</script>
57+
<style>
58+
.loader {
59+
border: 5px solid rgba(255, 255, 255, 0.1);
60+
border-radius: 50%;
61+
border-top: 5px solid #8a2be2;
62+
width: 50px;
63+
height: 50px;
64+
animation: spin 1s linear infinite;
65+
}
66+
@keyframes spin {
67+
0% { transform: rotate(0deg); }
68+
100% { transform: rotate(360deg); }
69+
}
70+
</style>
71+
</head>
72+
<body class="bg-dark text-gray-200 flex items-center justify-center h-screen">
73+
<div class="text-center">
74+
<div class="loader mx-auto mb-6"></div>
75+
<h2 class="text-2xl font-bold mb-2">Loading Leaderboard...</h2>
76+
<p class="text-gray-400">Please wait while we redirect you to the correct page.</p>
77+
</div>
78+
</body>
79+
</html>

0 commit comments

Comments
 (0)