From f911eea2273422e89b9ab75d0433a57269afa416 Mon Sep 17 00:00:00 2001 From: Renoir Boulanger Date: Mon, 21 Oct 2024 15:40:06 -0400 Subject: [PATCH] Stashing: Remove unused redirect --- components/global/GitHubPagesRedirect.vue | 66 -------------------- lib/runtime/index.ts | 1 - lib/runtime/page-redirect.ts | 75 ----------------------- middleware/redirects.ts | 27 -------- 4 files changed, 169 deletions(-) delete mode 100644 components/global/GitHubPagesRedirect.vue delete mode 100644 lib/runtime/page-redirect.ts delete mode 100644 middleware/redirects.ts diff --git a/components/global/GitHubPagesRedirect.vue b/components/global/GitHubPagesRedirect.vue deleted file mode 100644 index 38e82e51fe..0000000000 --- a/components/global/GitHubPagesRedirect.vue +++ /dev/null @@ -1,66 +0,0 @@ - - - diff --git a/lib/runtime/index.ts b/lib/runtime/index.ts index 581d117af1..1ad37784e3 100644 --- a/lib/runtime/index.ts +++ b/lib/runtime/index.ts @@ -3,7 +3,6 @@ export * from './nuxt-content-links' export * from './nuxt-content' export * from './nuxt-feed' export * from './nuxt' -export * from './page-redirect' export * from './tailwind' export * from './text-utils' export * from './utils' diff --git a/lib/runtime/page-redirect.ts b/lib/runtime/page-redirect.ts deleted file mode 100644 index cd8cfd03ae..0000000000 --- a/lib/runtime/page-redirect.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { Context } from '@nuxt/types' -import { Route } from 'vue-router' - -import { PUBLIC_BASE_URL } from '../consts' -import { IVueRouterLocation, INuxtContextIsserTriplet } from './nuxt' - -export type PageRedirect = [RegExp, string, true?] - -export type MaybeRedirectToTypeFn = (route: Route) => false | IVueRouterLocation - -export const createMaybeRedirectTo = ( - redirects: PageRedirect[], -): MaybeRedirectToTypeFn => (route: Route): false | IVueRouterLocation => { - const hasRedirect = redirects.find((m) => m[0].test(route.path)) - let out: false | IVueRouterLocation = false - if (hasRedirect && Array.isArray(hasRedirect) && hasRedirect[1]) { - let path = hasRedirect[1] - if (hasRedirect[2] === true) { - path = route.path.replace(hasRedirect[0], hasRedirect[1]) - } - out = { path } as IVueRouterLocation - } - return out -} - -/** - * We are trying to provide the following behavior: - * - * 1. When dev mode: use middleware to redirect - * 2. When static build (and for the desired build output): Serve an HTML file with redirect - */ -export const createIsStaticBuildRuntime = ( - ctx: INuxtContextIsserTriplet, -): boolean => { - const { isStatic = false, isDev = false } = ctx - const isProcessStatic = process.static - const out = - isStatic === true && (isStatic === isProcessStatic) === (isDev === false) - return out -} - -export interface IPageRedirectAsyncData { - isStaticBuildRuntime: boolean - shouldRedirect: boolean - shouldRedirectTo: false | IVueRouterLocation - to: false | IVueRouterLocation - baseUrl: string -} - -export const createPageRedirectAsyncData = ( - redirects: [RegExp, string, true?][], -) => (ctx: Context): IPageRedirectAsyncData => { - const resolveMaybeToLocation = createMaybeRedirectTo(redirects) - const isStaticBuildRuntime = createIsStaticBuildRuntime(ctx) - const shouldRedirect = isStaticBuildRuntime === false - const shouldRedirectTo = resolveMaybeToLocation(ctx.route) - let to: false | IVueRouterLocation = false - const baseUrl = PUBLIC_BASE_URL - if (shouldRedirectTo) { - if (shouldRedirect) { - ctx.redirect(shouldRedirectTo) - } - if (isStaticBuildRuntime) { - to = shouldRedirectTo - } - } - const out: IPageRedirectAsyncData = { - isStaticBuildRuntime, - shouldRedirect, - shouldRedirectTo, - to, - baseUrl, - } - return out -} diff --git a/middleware/redirects.ts b/middleware/redirects.ts deleted file mode 100644 index 5b34ecb190..0000000000 --- a/middleware/redirects.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Context } from '@nuxt/types' -import { - createMaybeRedirectTo, - /* */ -} from '../lib' - -const redirects: [RegExp, string, true?][] = [ - /* - [ - /^\/projets\/les-arnaques-sur-internet/i, - '/projects/les-arnaques-sur-internet', - ], - [ - /^\/projets\/les-arnaques-sur-internet\/type-descroquerie-sur-le-web-faire-du-bruit-pour-avoir-des-vues-de-page-de-medias-sociaux/i, - '/projects/type-descroquerie-sur-le-web-faire-du-bruit-pour-avoir-des-vues-de-page-de-medias-sociaux', - ], - */ -] - -const maybeRedirectTo = createMaybeRedirectTo(redirects) - -export default (ctx: Context) => { - const maybeRedirectPath = maybeRedirectTo(ctx.route) - if (maybeRedirectPath) { - return ctx.redirect(maybeRedirectPath) - } -}