Repository navigation
Expand file tree
/
Copy path404.html
More file actions
68 lines (57 loc) · 1.8 KB
/
Copy path404.html
File metadata and controls
68 lines (57 loc) · 1.8 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
---
layout: default
permalink: /404.html
---
<script>
function pad(num, size) {
num = num.toString();
while (num.length < size) num = "0" + num;
return num;
}
function redirect() {
let path = window.location.pathname;
let mutated = false;
const query = window.location.search;
if (path.endsWith('/')) {
path = path.slice(0, -1);
window.location.replace('{{site.url}}' + path);
return;
}
const re_bad_concat = new RegExp('^\/blog[0-9]+');
let matches = path.match(re_bad_concat);
if (matches) {
path = path.replace('blog', 'blog/');
window.location.replace('{{site.url}}' + path);
return;
}
// Uber hack: when I migrated my wordpress posts to github pages I did
// not realize the timestamps were not on my local time. This caused some
// dates to be shifted by a day. Try the next day if we didn't find the
// date.
const re = new RegExp('^\/blog\/([0-9]+)\/([0-9]+)\/([0-9]+)\/[a-z\-]+');
matches = path.match(re);
if (matches) {
const year = matches[1];
const month = matches[2];
const day = matches[3];
const old_date_str = [year, month, day].join('/');
const timestamp = Date.parse([year, month, day].join('-'));
const shifted_timestamp = timestamp + 1000 * 60 * 60 * 24;
const date = new Date(shifted_timestamp);
const new_date_str = [
date.getUTCFullYear(),
pad(date.getUTCMonth() + 1, 2),
pad(date.getUTCDate(), 2)
].join('/');
path = path.replace(old_date_str, new_date_str);
mutated = true;
}
if (query == '' && mutated) {
window.location.replace('{{site.url}}' + path + '?redirected=1');
return;
}
}
redirect();
</script>
# 404
Page not found! :(