Skip to content

Commit 24671c7

Browse files
author
fadeouter
committed
update
1 parent 8250100 commit 24671c7

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

nk/projects/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Redirection</title>
7+
</head>
8+
<body>
9+
<h1>Redirecting...</h1>
10+
<script src="../redirect.js"></script>
11+
</body>
12+
</html>

nk/redirect.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Fetch the content of the 'urls.md' file
2+
fetch('urls.md')
3+
.then(response => {
4+
if (!response.ok) {
5+
throw new Error('Network response was not ok ' + response.statusText);
6+
}
7+
return response.text();
8+
})
9+
.then(data => {
10+
// Parse the content of the file
11+
const lines = data.split('\n');
12+
const mappings = {};
13+
14+
lines.forEach(line => {
15+
const [key, url] = line.split('\t');
16+
if (key && url) {
17+
mappings[key.trim()] = url.trim();
18+
}
19+
});
20+
21+
// Get the last part of the URL path
22+
const path = window.location.pathname.split('/').filter(Boolean).pop();
23+
24+
// Check if the path exists in the mappings and redirect
25+
if (path in mappings) {
26+
window.location.href = mappings[path];
27+
} else {
28+
document.body.innerHTML = '<h1>404: Page Not Found</h1>';
29+
}
30+
})
31+
.catch(error => {
32+
console.error('There was a problem with the fetch operation:', error);
33+
document.body.innerHTML = '<h1>Error loading redirection data</h1>';
34+
});

nk/urls.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
projects https://hello.com
2+
some-website https://google.com
3+
another-example https://example.com

0 commit comments

Comments
 (0)