templates for self-hosting game jams (or any other kind of jam tbh)
1import.meta.glob([
2 '../images/**',
3 '../fonts/**',
4]);
5
6const startContent = document.getElementById('startDate') ? document.getElementById('startDate').textContent : null;
7const startDate = document.getElementById('startDate') ? document.getElementById('startDate').getAttribute('data-raw') : null;
8const endContent = document.getElementById('endDate') ? document.getElementById('endDate').textContent : null;
9const endDate = document.getElementById('endDate') ? document.getElementById('endDate').getAttribute('data-raw') : null;
10
11const numEntries = 0; // fix this later to be dynamic
12
13// Date formatting stuff. You probably only need to touch locale and time zone.
14const locale = 'en-US';
15const timeZone = 'America/Chicago';
16
17// DON'T EDIT BELOW THIS LINE
18// unless you know what you're doing.
19
20const start = new Date(startDate);
21const end = new Date(endDate);
22const now = Date.now();
23
24const dateElt = document.getElementById('dates');
25
26const daysElt = document.getElementById('days');
27const hoursElt = document.getElementById('hours');
28const minutesElt = document.getElementById('minutes');
29const secondsElt = document.getElementById('seconds');
30
31const list = document.getElementById('list');
32
33const dayMult = 24*60*60;
34const hourMult = 60*60;
35const minuteMult = 60;
36
37const countdownTick = () => {
38 const now = Date.now();
39 let diff;
40 if (now < start.getTime()) {
41 // Jam hasn't started yet
42 diff = (start.getTime() - now) / 1000; // get total # of seconds
43 } else if (now < end.getTime()) {
44 // Jam has started but not ended
45 diff = (end.getTime() - now) / 1000;
46 } else {
47 // Jam has ended
48 dates.innerHTML = `The jam is now over. It ran from <b>${startContent}</b> to <b>${endContent}</b>. <a href="submissions.html">View ${numEntries} ${numEntries !== 1 ? 'entries' : 'entry'}`
49 }
50
51 if (diff) {
52 const days = Math.floor(diff / dayMult);
53 diff = diff - (days * dayMult);
54 const hours = Math.floor(diff / hourMult);
55 diff = diff - (hours * hourMult);
56 const minutes = Math.floor(diff / minuteMult);
57 diff = diff - (minutes * minuteMult);
58 const seconds = Math.floor(diff);
59 daysElt.textContent = days;
60 hoursElt.textContent = hours;
61 minutesElt.textContent = minutes;
62 secondsElt.textContent = seconds;
63 }
64}
65
66if (document.querySelector('.clock')) {
67 countdownTick();
68 if (now < end.getTime()) {
69 setInterval(() => {
70 countdownTick();
71 }, 1000);
72 }
73}