Skip to content

Commit 6e9a140

Browse files
author
Yassine El Haddad
committed
simplified 404 page logic
1 parent b38896f commit 6e9a140

2 files changed

Lines changed: 25 additions & 57 deletions

File tree

Lines changed: 25 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,58 @@
11
<template>
22
<div class="custom-container">
3+
<iframe v-if="showIframe" :src="iframeSrc" style="width: 100%; height: 100vh; border: none;"></iframe>
34
</div>
45
</template>
56

6-
77
<script setup>
88
import { useRoute, useRouter } from "vue-router";
99
import { onMounted, ref } from "vue";
1010
import { pagesData } from "../../.temp/internal/pagesData.js";
11-
import redirects from './redirects.json';
1211
1312
const route = useRoute();
1413
const router = useRouter();
15-
const allPages = ref([]);
16-
17-
// Function to escape special characters in a string for use in a regular expression
18-
function escapeRegExp(string) {
19-
return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
20-
}
21-
22-
const redirectionURL = async () => {
23-
if (route.path.startsWith('/index.html?')) {
24-
// Extract the part after the ?
25-
const key = route.path.split('?')[1];
26-
// Check if this key exists in the redirects
27-
if (key in redirects) {
28-
// If it does, redirect to the associated path
29-
router.push(redirects[key]);
30-
return true;
31-
}
32-
}
33-
34-
for (let [from, to] of Object.entries(redirects)) {
35-
// Existing code for paths without special characters
36-
const escapedFrom = escapeRegExp(from);
37-
if (route.path.search(escapedFrom) !== -1) {
38-
const path = route.path.replace(new RegExp(escapedFrom, 'g'), to);
39-
// If match is found, return true
40-
router.push(path);
41-
return true;
42-
}
43-
}
44-
// If no match is found, return false
45-
return false;
46-
};
14+
const showIframe = ref(false);
15+
const iframeSrc = ref("");
4716
4817
const getRecursiveLevelPath = (child, rootPath) => {
4918
let haveSolution = false;
5019
5120
if (haveSolution) return;
5221
53-
if(child.children?.length > 0) {
22+
if (child.children?.length > 0) {
5423
for (let h of child.children) {
55-
const path = rootPath + "/" + h.link
24+
const path = rootPath + "/" + h.link;
5625
5726
if (path.search(route.path) !== -1) {
58-
router.push(path)
59-
haveSolution = true
27+
router.push(path);
28+
haveSolution = true;
6029
return;
6130
}
6231
6332
if (child.children.length > 0) {
64-
getRecursiveLevelPath(h, rootPath)
33+
getRecursiveLevelPath(h, rootPath);
6534
}
6635
}
6736
}
6837
};
6938
7039
onMounted(async () => {
71-
// If a redirect was performed, stop checking the other techniques
72-
if (await redirectionURL()) {
73-
return;
74-
}
75-
76-
// If no match found in JSON redirects, then check the existing techniques
7740
const values = Object?.values(pagesData);
7841
7942
for (let value of values) {
8043
const res = await value();
81-
8244
let rootPath = res.path;
8345
84-
if (rootPath.at(-1) === "/")
46+
if (rootPath.at(-1) === "/") {
8547
rootPath = rootPath.slice(0, -1);
48+
}
8649
87-
if(res.headers?.length > 0) {
50+
if (res.headers?.length > 0) {
8851
for (let h of res.headers) {
89-
const path = rootPath + "/" + h.link
52+
const path = rootPath + "/" + h.link;
9053
91-
if (path.search(route.path) !== -1){
92-
router.push(path)
54+
if (path.search(route.path) !== -1) {
55+
router.push(path);
9356
return;
9457
}
9558
getRecursiveLevelPath(h, rootPath);
@@ -99,15 +62,23 @@ onMounted(async () => {
9962
10063
if (route.fullPath.startsWith('/legacy')) {
10164
const newPath = route.fullPath.replace('/legacy', '/cloudlinuxos');
102-
// router.push(newPath);
10365
window.location.href = newPath;
10466
} else if (route.fullPath.startsWith('/shared')) {
10567
const newPath = route.fullPath.replace('/shared', '/cloudlinuxos');
10668
router.push(newPath);
10769
window.location.href = newPath;
10870
} else {
109-
window.location.href = '/not-found.html';
71+
// Show the iframe and set the source to 'not-found.html'
72+
showIframe.value = true;
73+
iframeSrc.value = '/not-found.html';
11074
}
111-
11275
});
11376
</script>
77+
78+
<style>
79+
.custom-container {
80+
position: relative;
81+
width: 100%;
82+
height: 100vh;
83+
}
84+
</style>

docs/.vuepress/theme/layouts/redirects.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)