Skip to content

Commit

Permalink
feat: add 404 and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
prplwtf committed Oct 16, 2024
1 parent 1eed9b2 commit 4e67b0f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ document.addEventListener("DOMContentLoaded", (async () => {

Route(window.location.hash)
}, 10);
}))
}))

function Error() {
ModifyAppTitle()
ProgressBar(100)
return App.innerHTML = `An unknown error occured, check your browser console for more information.`
}
2 changes: 1 addition & 1 deletion src/components/elements/NavigationBarElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function NavigationBarElement() {
<div class="col-auto">
${LinkElement()}
<a href="#blog">
<button type="button" class="btn ${ButtonClass} rounded-5">
<button type="button" class="btn ${ButtonClass} rounded-pill">
posts
<span class="ripple-surface"></span>
</button>
Expand Down
16 changes: 16 additions & 0 deletions src/components/sections/NotfoundSection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function NotfoundSection() {
return `
<p class="text-center">
<i class="bi bi-cup h1 me-2 mt-1"></i>
<span class="h1">404</span>
</p>
<p class="text-center">
<a href="#">
<button type="button" class="btn btn-primary rounded-pill mt-2">
back to safety
<span class="ripple-surface"></span>
</button>
</a>
</p>
`
}
1 change: 1 addition & 0 deletions src/components/sections/ReadSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ async function ReadSection() {

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

ModifyAppTitle(Post.Content.replace(".md", ""))
Expand Down
1 change: 1 addition & 0 deletions src/router/Import.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function Import(url, id, callback) {

script.onerror = function() {
console.error(`Failed to load script with id "${id}"`);
return Error();
};

script.src = url;
Expand Down
11 changes: 8 additions & 3 deletions src/router/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ async function Route(view) {
})
}

ModifyAppTitle()
ProgressBar(100)
return App.innerHTML = `An unknown error occured, check your browser console for more information.`
// #404
console.info(`View ${view} not found, returning 404.`)
return Import("./src/components/sections/NotfoundSection.js", "Section", function() {
App.innerHTML = `${NotfoundSection()}`
ModifyAppTitle("404")
Effects()
ProgressBar(100)
})
}

window.addEventListener("hashchange", function() {
Expand Down
2 changes: 1 addition & 1 deletion src/router/Unload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ function Unload(id) {
if (script) {
script.parentNode.removeChild(script);
} else {
console.warn(`No script found with id "${id}".`);
return console.info(`Failed to unload script with id "${id}"`);
}
}

0 comments on commit 4e67b0f

Please sign in to comment.