-
Notifications
You must be signed in to change notification settings - Fork 0
/
404.html
138 lines (119 loc) · 3.53 KB
/
404.html
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html>
<head>
<title>Page not found</title>
<script type="text/javascript">
window.isErrorPage = true;
window.errorCode = '404';
</script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="Page not found">
<script src="/scripts/scripts.js" type="module" crossorigin="use-credentials"></script>
<script type="module">
import { sampleRUM } from '/scripts/lib-franklin.js';
import { fetchPlaceholders } from '/scripts/scripts.js';
function appendImage(img) {
const image = document.createElement('img');
const src = img;
image.setAttribute('src', src);
const alt = 'Error Image';
image.setAttribute('alt', alt);
const imageContainerEl = document.querySelector('#img-container');
imageContainerEl.appendChild(image);
}
async function getPlaceholders() {
try {
const placeholders = await fetchPlaceholders();
const { message, image } = placeholders;
const errMessageEl = document.querySelector('.error-message');
appendImage(image)
errMessageEl.innerText = message || 'Page failed to load';
} catch(err) {
console.error('Failed to parse the placeholder json', err);
}
}
window.addEventListener('load', () => {
// make the API call to get the placeholder items.
getPlaceholders();
if (document.referrer) {
const { origin, pathname } = new URL(document.referrer);
if (origin === window.location.origin) {
const backBtn = document.createElement('a');
backBtn.classList.add('button', 'error-button-back');
backBtn.href = pathname;
backBtn.textContent = 'Go back';
backBtn.title = 'Go back';
const btnContainer = document.querySelector('.button-container');
btnContainer.append(backBtn);
}
}
let url = window.location.href;
if(url.endsWith("/")) url = url.slice(0, -1);
const newUrl = url.slice(0, url.lastIndexOf('/'));
const goHomeLink = newUrl ? newUrl : "/";
const goHomeBtn = document.querySelector(".error-button-home")
goHomeBtn.setAttribute('href', goHomeLink);
sampleRUM('404', { source: document.referrer, target: window.location.href });
});
</script>
<link rel="stylesheet" href="/styles/styles.css">
<style>
main.error {
min-height: calc(100vh - var(--nav-height));
margin-top: var(--nav-height);
text-align: center;
}
header {
top: 0;
left: 0;
right: 0;
}
main.error > div {
padding: 1em;
}
h1 {
font-size: 6rem;
color: var(--button-color);
margin: 0;
}
h2 {
font-size: var(--heading-font-size-l);
color: var(--color-catalina-blue);
}
.button-container {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.button-container a:any-link {
margin: 0.5em 0.5em;
}
#img-container {
margin: 0 auto;
max-width: 70%;
}
@media (min-width: 768px) {
h1 {
font-size: 10rem;
}
svg {
max-width: 70%;
}
}
</style>
</head>
<body>
<header></header>
<main class="error">
<div class="section">
<h2 class="error-message"></h2>
<p class="button-container">
<a href="/" class="button secondary error-button-home">Go home</a>
</p>
<div id="img-container"></div>
</div>
</main>
<footer></footer>
</body>
</html>