Skip to content

Commit d7be1e7

Browse files
authored
Merge pull request #23 from TrickfireRobotics/adamseth2/automate_deadline
Connected deadline text to be dynamic google doc
2 parents 2b14eda + e8c85d5 commit d7be1e7

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

assets/javascript/deadlineText.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//DO NOT CHANGE DELIMITERs
2+
const DELIMITER_BEG =
3+
'DO NOT DELETE THIS TEXT AND INCLUDE A SPACE AFTER COLON: ';
4+
// 2 Ending because for some reason fetching from google doc has to
5+
const DELIMITER_END1 = '</span>';
6+
const DELIMITER_END2 = '"';
7+
8+
const deadlineElements = document.querySelectorAll('[data-deadline]');
9+
10+
fetch(
11+
//public view only url
12+
//trickfirerobotics@gmail.com
13+
'https://docs.google.com/document/d/1tRysVWzUv-sKNg6lWe7n-CvKLZU0HNW3SZiIs19d09Q/edit?usp=sharing'
14+
)
15+
.then(res => {
16+
//check to make sure API works
17+
if (!res.ok) {
18+
throw new error('DEADLINE TEXT API NOT WORKING');
19+
}
20+
return res.text();
21+
})
22+
.then(text => {
23+
let indexBeg = text.indexOf(DELIMITER_BEG) + DELIMITER_BEG.length;
24+
let indexEnd = Math.min(
25+
text.indexOf(DELIMITER_END1, indexBeg),
26+
text.indexOf(DELIMITER_END2, indexBeg)
27+
);
28+
//Catches if the DELIMITER isn't found
29+
if (indexBeg == -1 + DELIMITER_BEG.length || indexEnd == -1) {
30+
throw new Error('DELIMITER WAS NOT FOUND');
31+
}
32+
33+
const deadlineText = `Deadline: ${text.substring(indexBeg, indexEnd)}`;
34+
//safety check to make sure it didn't go over
35+
if (deadlineText.length > 100) {
36+
throw new Error('TEXT WAS OVER 100 CHARS');
37+
}
38+
deadlineElements.forEach(ele => {
39+
ele.innerText = deadlineText;
40+
});
41+
})
42+
.catch(error => {
43+
console.error(error);
44+
});

assets/moduleHtml/footer.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@
5757
</p>
5858
</div>
5959
<script>
60-
console.log(document.getElementById('copyright-text').innerText);
6160
let copyrightTextElement =
6261
document.getElementById('copyright-text');
6362
let currentYear = new Date().getFullYear();
64-
console.log(currentYear);
6563
copyrightTextElement.innerText =
6664
copyrightTextElement.innerText.replace('2022', currentYear);
6765
</script>

join_us.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
$('#footer').load('./assets/moduleHtml/footer.html');
5151
});
5252
</script>
53+
<!-- Updates Deadline text dynamicaly -->
54+
<script
55+
type="module"
56+
async
57+
src="./assets/javascript/deadlineText.js"
58+
></script>
5359
</head>
5460

5561
<body>
@@ -102,9 +108,10 @@ <h1>Why Join?</h1>
102108
>
103109
TrickFire Robotics Application Link
104110
</a>
105-
<br/>
106-
<b>Deadline: Between June 20th and July 15th</b>
107-
111+
<br />
112+
<b data-deadline>
113+
Deadline: Please check the form above</b
114+
>
108115
</p>
109116
</div>
110117
</div>
@@ -147,15 +154,18 @@ <h1>Why Join?</h1>
147154
>
148155
TrickFire Robotics Application Link
149156
</a>
150-
<br/>
151-
<b>Deadline: Between June 20th and July 15th</b>
157+
<br />
158+
<b data-deadline>
159+
Deadline: Please check the form above</b
160+
>
152161
</p>
153162
</div>
154163
</div>
155164
<div class="space-after-rows"></div>
156165
</section>
157166

158167
<footer id="footer"></footer>
168+
159169
<script
160170
src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js"
161171
integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx"

0 commit comments

Comments
 (0)