Skip to content

Commit 4e67b0f

Browse files
committed
feat: add 404 and stuff
1 parent 1eed9b2 commit 4e67b0f

File tree

7 files changed

+35
-6
lines changed

7 files changed

+35
-6
lines changed

src/App.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ document.addEventListener("DOMContentLoaded", (async () => {
1818

1919
Route(window.location.hash)
2020
}, 10);
21-
}))
21+
}))
22+
23+
function Error() {
24+
ModifyAppTitle()
25+
ProgressBar(100)
26+
return App.innerHTML = `An unknown error occured, check your browser console for more information.`
27+
}

src/components/elements/NavigationBarElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function NavigationBarElement() {
3030
<div class="col-auto">
3131
${LinkElement()}
3232
<a href="#blog">
33-
<button type="button" class="btn ${ButtonClass} rounded-5">
33+
<button type="button" class="btn ${ButtonClass} rounded-pill">
3434
posts
3535
<span class="ripple-surface"></span>
3636
</button>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function NotfoundSection() {
2+
return `
3+
<p class="text-center">
4+
<i class="bi bi-cup h1 me-2 mt-1"></i>
5+
<span class="h1">404</span>
6+
</p>
7+
<p class="text-center">
8+
<a href="#">
9+
<button type="button" class="btn btn-primary rounded-pill mt-2">
10+
back to safety
11+
<span class="ripple-surface"></span>
12+
</button>
13+
</a>
14+
</p>
15+
`
16+
}

src/components/sections/ReadSection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ async function ReadSection() {
33

44
let PostContentFile = `${window.location.hash.replace("#read/", "")}.md`
55
let Post = window.Blogs.find(item => item.Content === PostContentFile)
6+
if(!Post) { return window.location = "#404" }
67
let PostContentPath = `./posts/${Post.Content}`
78

89
ModifyAppTitle(Post.Content.replace(".md", ""))

src/router/Import.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function Import(url, id, callback) {
1313

1414
script.onerror = function() {
1515
console.error(`Failed to load script with id "${id}"`);
16+
return Error();
1617
};
1718

1819
script.src = url;

src/router/Route.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ async function Route(view) {
4343
})
4444
}
4545

46-
ModifyAppTitle()
47-
ProgressBar(100)
48-
return App.innerHTML = `An unknown error occured, check your browser console for more information.`
46+
// #404
47+
console.info(`View ${view} not found, returning 404.`)
48+
return Import("./src/components/sections/NotfoundSection.js", "Section", function() {
49+
App.innerHTML = `${NotfoundSection()}`
50+
ModifyAppTitle("404")
51+
Effects()
52+
ProgressBar(100)
53+
})
4954
}
5055

5156
window.addEventListener("hashchange", function() {

src/router/Unload.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ function Unload(id) {
33
if (script) {
44
script.parentNode.removeChild(script);
55
} else {
6-
console.warn(`No script found with id "${id}".`);
6+
return console.info(`Failed to unload script with id "${id}"`);
77
}
88
}

0 commit comments

Comments
 (0)