Skip to content

Commit bf86302

Browse files
committed
update: Updates to files
1 parent 8cf8d6f commit bf86302

File tree

8 files changed

+53
-254
lines changed

8 files changed

+53
-254
lines changed

site/404.html

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,32 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>Redirecting... | Testify</title>
77
<script>
8-
// This script helps handle GitHub Pages routing
8+
// This script helps handle routing
99
(function() {
1010
// Split the URL path
1111
const path = window.location.pathname;
1212
const search = window.location.search;
1313

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';
14+
// Check if it's a leaderboard route
15+
if (path.includes('/leaderboard/')) {
16+
const pathParts = path.split('/');
17+
const lastPart = pathParts[pathParts.length - 1];
18+
19+
if (lastPart === 'global') {
20+
// Go to global leaderboard
21+
window.location.href = '/global-leaderboard.html';
22+
} else if (lastPart && lastPart !== 'leaderboard') {
23+
// Store guild ID and redirect to leaderboard page
24+
sessionStorage.setItem('guildId', lastPart);
25+
window.location.href = '/leaderboard.html';
26+
} else {
27+
// Default to home page
28+
window.location.href = '/';
29+
}
30+
} else {
31+
// Default to home page for other routes
32+
window.location.href = '/';
33+
}
1934
})();
2035
</script>
2136
<style>

site/global-leaderboard.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
66
<title>Testify - Global Leaderboard</title>
77
<script src="https://cdn.tailwindcss.com"></script>
8-
<link rel="stylesheet" href="./css/styles.css" />
9-
<link rel="stylesheet" href="./css/leaderboard.css" />
8+
<link rel="stylesheet" href="/css/styles.css" />
9+
<link rel="stylesheet" href="/css/leaderboard.css" />
1010
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
1111
<link rel="icon" type="image/png" href="https://i.postimg.cc/KznLsF43/Testi-1.png" />
1212
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />

site/js/api-config.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

site/js/global-leaderboard.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,11 @@ 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-
6146
// Functions
6247
async function fetchGlobalLeaderboard(page) {
6348
try {
64-
const apiUrl = getApiEndpoint(`/api/leaderboard/global?page=${page}`);
65-
66-
const response = await fetch(apiUrl);
49+
// Use relative API endpoint
50+
const response = await fetch(`/api/leaderboard/global?page=${page}`);
6751

6852
if (!response.ok) {
6953
throw new Error(`Server returned ${response.status}: ${response.statusText}`);
@@ -100,7 +84,7 @@ document.addEventListener('DOMContentLoaded', function() {
10084
// Try to fetch user info from Discord API
10185
let userInfo;
10286
try {
103-
const userResponse = await fetch(getApiEndpoint(`/api/user/${user._id}`));
87+
const userResponse = await fetch(`/api/user/${user._id}`);
10488
if (userResponse.ok) {
10589
userInfo = await userResponse.json();
10690
}

site/js/leaderboard.js

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

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();
22+
// Extract guild ID from URL
23+
const pathParts = window.location.pathname.split('/');
24+
guildId = pathParts[pathParts.length - 1];
25+
26+
// Also check session storage as fallback
27+
if (!guildId || guildId === 'leaderboard.html') {
28+
guildId = sessionStorage.getItem('guildId');
29+
}
3930

4031
if (!guildId) {
4132
showError("No guild ID found. Please go back and try again.");
@@ -71,36 +62,14 @@ document.addEventListener('DOMContentLoaded', function() {
7162
});
7263

7364
globalBtn.addEventListener('click', () => {
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-
}
65+
window.location.href = '/leaderboard/global';
8166
});
8267

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-
9868
// Functions
9969
async function fetchLeaderboard(page) {
10070
try {
101-
const apiUrl = getApiEndpoint(`/api/leaderboard/${guildId}?page=${page}`);
102-
103-
const response = await fetch(apiUrl);
71+
// Use relative API endpoint
72+
const response = await fetch(`/api/leaderboard/${guildId}?page=${page}`);
10473

10574
if (!response.ok) {
10675
throw new Error(`Server returned ${response.status}: ${response.statusText}`);
@@ -118,7 +87,7 @@ document.addEventListener('DOMContentLoaded', function() {
11887
// Update guild info if available
11988
if (data.guildId) {
12089
try {
121-
const discordApiResponse = await fetch(getApiEndpoint(`/api/guild/${data.guildId}`));
90+
const discordApiResponse = await fetch(`/api/guild/${data.guildId}`);
12291
if (discordApiResponse.ok) {
12392
const guildData = await discordApiResponse.json();
12493
guildNameEl.textContent = guildData.name || 'Guild Leaderboard';
@@ -157,7 +126,7 @@ document.addEventListener('DOMContentLoaded', function() {
157126
// Try to fetch user info from Discord API
158127
let userInfo;
159128
try {
160-
const userResponse = await fetch(getApiEndpoint(`/api/user/${user.User}`));
129+
const userResponse = await fetch(`/api/user/${user.User}`);
161130
if (userResponse.ok) {
162131
userInfo = await userResponse.json();
163132
}

site/leaderboard.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
66
<title>Testify - Guild Leaderboard</title>
77
<script src="https://cdn.tailwindcss.com"></script>
8-
<link rel="stylesheet" href="./css/styles.css" />
9-
<link rel="stylesheet" href="./css/leaderboard.css" />
8+
<link rel="stylesheet" href="/css/styles.css" />
9+
<link rel="stylesheet" href="/css/leaderboard.css" />
1010
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
1111
<link rel="icon" type="image/png" href="https://i.postimg.cc/KznLsF43/Testi-1.png" />
1212
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
1313
<script>
14+
// Handle direct URL navigation to save guild ID from URL path
15+
document.addEventListener('DOMContentLoaded', function() {
16+
const path = window.location.pathname;
17+
const pathParts = path.split('/');
18+
const lastPart = pathParts[pathParts.length - 1];
19+
20+
// If we have a guild ID in the path
21+
if (lastPart && lastPart !== 'leaderboard.html' && !isNaN(lastPart)) {
22+
sessionStorage.setItem('guildId', lastPart);
23+
}
24+
});
25+
1426
tailwind.config = {
1527
darkMode: "class",
1628
theme: {

site/mock-data/global-leaderboard-example.json

Lines changed: 0 additions & 71 deletions
This file was deleted.

site/mock-data/leaderboard-example.json

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)