-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetUpdatedResume.js
More file actions
70 lines (63 loc) · 1.94 KB
/
getUpdatedResume.js
File metadata and controls
70 lines (63 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Return the URL of the file with the most recent update time in its title (last argument of _ delimited before file extension)
function getUpdatedResume() {
return fetch(
"https://api.github.com/repos/MarkCarsonDev/markcarson.dev/contents/downloads/resume"
)
.then((response) => response.json())
.then((data) => {
let latestFile = null;
let latestDate = null;
for (let file of data) {
const fileName = file.name;
const match = fileName.match(/_(\d{6})\./);
if (match) {
const dateStr = match[1];
const year = parseInt(dateStr.slice(0, 2)) + 2000;
const month = parseInt(dateStr.slice(2, 4)) - 1;
const day = parseInt(dateStr.slice(4, 6));
const fileDate = new Date(year, month, day);
if (!latestDate || fileDate > latestDate) {
latestDate = fileDate;
latestFile = fileName;
}
}
}
if (latestFile) {
const resumeLink = document.getElementById("resume");
const resumeURL = "/downloads/resume/" + latestFile;
resumeLink.href = resumeURL;
return resumeURL;
}
})
.catch((error) => {
console.error("Error fetching updated resume:", error);
throw error;
});
}
// Call the function to update the resume link
getUpdatedResume();
// -- Bandaid solution until reverse proxy/SSSG is ready -- //
function openResume() {
// Find the element with ID 'resume' and click it
const resumeElement = document.getElementById("resume");
if (resumeElement) {
window.location.href = resumeElement.href;
open(resumeElement.href, "_blank");
}
}
// Support /#resume to redirect on already loaded page to the resume link
function resumeFragment() {
// Check if the URL has the fragment '#resume'
if (window.location.hash === "#resume") {
openResume();
}
}
function redirectResume() {
if (window.location.hash === "#resume") {
openResume();
}
}
// Call the redirect function on page load
document.addEventListener("DOMContentLoaded", function () {
redirectResume();
});