-
Notifications
You must be signed in to change notification settings - Fork 1
/
404.html
40 lines (38 loc) · 1.39 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Short URL App</title>
<script type="text/javascript">
(function () {
fetch('meta.json')
.then(response => response.json())
.then(meta => {
let fragment = location.pathname.split('/').pop();
let info = meta[fragment];
console.log(`info, ${info}`);
if (info) {
let metaTag = document.createElement('meta');
metaTag.property = 'og:description';
metaTag.content = info['og-description'];
document.getElementsByTagName('head')[0].appendChild(metaTag);
}
})
.catch(error => {
console.log(error);
});
fetch(`routes.json?t=${Date.now()}`)
.then(response => response.json())
.then(routes => {
let fragment = location.pathname.split('/').pop();
let url = routes[fragment];
console.log(`${fragment}, ${url}`);
location.href = url ? url : './index.html';
})
.catch(error => {
console.log(error);
});
})();
</script>
</head>
</html>