fix: google snapshots error #649
This commit is contained in:
Generated
+1212
-183
File diff suppressed because it is too large
Load Diff
@@ -110,6 +110,9 @@ const routes: RouteNode[] = [
|
||||
{
|
||||
path: '/search',
|
||||
page: 'pages/Search',
|
||||
guard: () => {
|
||||
return guard.googleSnapshotRedirect();
|
||||
},
|
||||
},
|
||||
// tags
|
||||
{
|
||||
|
||||
@@ -401,6 +401,25 @@ export const initAppSettingsStore = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
export const googleSnapshotRedirect = () => {
|
||||
const gr: TGuardResult = { ok: true };
|
||||
const searchStr = new URLSearchParams(window.location.search)?.get('q') || '';
|
||||
if (window.location.host !== 'webcache.googleusercontent.com') {
|
||||
return gr;
|
||||
}
|
||||
if (searchStr.indexOf('cache:') === 0 && searchStr.includes(':http')) {
|
||||
const redirectUrl = `http${searchStr.split(':http')[1]}`;
|
||||
const pathname = redirectUrl.replace(new URL(redirectUrl).origin, '');
|
||||
console.log('googleSnapshotUrl', window.location.href);
|
||||
|
||||
gr.ok = false;
|
||||
gr.redirect = pathname || '/';
|
||||
return gr;
|
||||
}
|
||||
|
||||
return gr;
|
||||
};
|
||||
|
||||
let appInitialized = false;
|
||||
export const setupApp = async () => {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user