Skip to content

Commit

Permalink
Try fix over-prevention
Browse files Browse the repository at this point in the history
  • Loading branch information
utensil committed Nov 6, 2024
1 parent 77a6e50 commit 0d92940
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions assets/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
const redirectConfig = [
// {regex: /^\/example$/, redirect: "/example.html"},
/* {regex: /\/.*\.xml$/, redirect: (path) => path.replace('.xml', '.html')} */
{regex: /.*/, redirect: "/lean4/index.html"}
{regex: /.*/, redirect: "/lean4/index-non-exist.html"}
];

function redirectToPage() {
const referrer = document.referrer;
let path = referrer && referrer !== window.location.href && !referrer.includes('404.html') ? new URL(referrer).pathname : '/formal-land/';
const referrer = document.referrer || window.location.href;
let path = referrer && !referrer.includes('404.html') ? new URL(referrer).pathname : '/formal-land/';
console.log('referrer:', path);
const pathParts = path.split('/');
path = pathParts.length > 2 ? '/' + pathParts.slice(2).join('/') : path;
Expand All @@ -50,10 +50,10 @@
if (rule.regex.test(path)) {
const redirectTo = typeof rule.redirect === 'function' ? rule.redirect(path) : rule.redirect;
if (redirectTo && !recentRedirects.includes(redirectTo)) {
if (recentRedirects.length >= 5) {
if (recentRedirects.length >= 3) {
recentRedirects.shift();
}
recentRedirects.push(redirectTo);
recentRedirects.push(path);
localStorage.setItem('recentRedirects', JSON.stringify(recentRedirects));
window.location.href = '/' + pathParts[1] + redirectTo;
break;
Expand Down

0 comments on commit 0d92940

Please sign in to comment.