-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
32 lines (30 loc) · 858 Bytes
/
app.js
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
// This just redirects the old `?post=slug` style of link
// to keep them alive
const [folder, fileExtension] = window.location.pathname.split(".");
const urlParams = new URLSearchParams(window.location.search);
const postSlug = urlParams.get("post");
const redirectIfValid = async (url) => {
return await fetch(fixedPostPath)
.then((res) => {
if (res.status >= 400) {
console.error(res);
return;
}
window.location.replace(url);
})
.catch((err) => console.error(err));
};
if (postSlug) {
try {
const fixedPostUrl = [
window.location.origin,
folder,
"/",
postSlug,
fileExtension,
].join("");
redirectIfValid(fixedPostUrl);
} catch (e) {
console.log(e);
}
}