Skip to content
Snippets Groups Projects
Unverified Commit ae913eef authored by Jonas Zohren's avatar Jonas Zohren :speech_balloon:
Browse files

Add fuzzy search for valid shortlink on 404 page

parent ee8641c7
Branches
No related tags found
No related merge requests found
...@@ -10,11 +10,22 @@ ...@@ -10,11 +10,22 @@
</head> </head>
<body> <body>
<section class="hero is-primary is-bold"> <section class="hero is-small is-primary is-bold">
<div class="hero-body"> <div class="hero-body">
<div class="container has-text-centered"> <div class="container has-text-centered">
<h1 class="title">404 Not Found</h1> <h1 class="title">404 - Diese Seite existiert nicht</h1>
<h2 class="subtitle">Diese Seite existiert nicht 😞</h2> </div>
</div>
</section>
<section class="is-invisible hero is-success is-bold" id="suggestion-section">
<div class="hero-body">
<div class="container has-text-centered">
<h2 class="subtitle">Vielleicht suchst du nach</h2>
<h1 class="title is-family-monospace">
<a id="suggestion-href" style="text-decoration: underline;" href="#">
oh14.de/<span id="suggestion-text">test</span>
</a>
</h1>
</div> </div>
</div> </div>
</section> </section>
...@@ -29,7 +40,6 @@ ...@@ -29,7 +40,6 @@
<div class="column is-5"> <div class="column is-5">
<div class="container"> <div class="container">
<p class="is-size-5">Das ist jetzt blöd gelaufen.</p> <p class="is-size-5">Das ist jetzt blöd gelaufen.</p>
<p>Vielleicht möchtest du Folgendes ausprobieren:</p>
<div class="buttons medium-margin-top"> <div class="buttons medium-margin-top">
<a href="https://fsinfo.cs.tu-dortmund.de" class="button is-primary"> <a href="https://fsinfo.cs.tu-dortmund.de" class="button is-primary">
Zur Startseite Zur Startseite
...@@ -50,6 +60,27 @@ ...@@ -50,6 +60,27 @@
</body> </body>
</html> </html>
<script>if (document.referrer !== "") { <script>
if (document.referrer !== "") {
document.getElementById("goback").classList.remove("is-invisible") document.getElementById("goback").classList.remove("is-invisible")
}</script> }
\ No newline at end of file </script>
<script src="cdnjs.cloudflare.com/fuse.js@6.4.6.js"></script>
<script>
async function addFuzzySearch() {
const vanityMap = await (await fetch("./vanitymap.json")).json()
const keys = Object.keys(vanityMap);
const fuse = new Fuse(keys, {})
const pathToSearchFor = window.location.pathname.replace("/", "").replace(".html", "").trim();
const results = fuse.search(pathToSearchFor)
if (results.length !== 0) {
const bestShortlink = results[0].item;
const bestHref = vanityMap[bestShortlink];
document.getElementById("suggestion-text").innerText = bestShortlink;
document.getElementById("suggestion-href").href = bestHref;
document.getElementById("suggestion-section").classList.remove("is-invisible");
}
}
addFuzzySearch()
</script>
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment