Skip to content

Commit

Permalink
Add redirects for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cdedreuille committed Jul 9, 2024
1 parent 480b096 commit e7e8f78
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
16 changes: 2 additions & 14 deletions apps/frontpage/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { cookieRenderId } from './constants';
import { docsVersionsRedirects } from './redirects/docs-versions-redirects';
import { RedirectData } from './redirects/types';
import { docsRenderersRedirects } from './redirects/docs-renderers-redirects';
import { docsCommonRedirects } from './redirects/docs-common-redirects';
import { listOfRedirects } from './redirects/redirects';

export async function middleware(request: NextRequest) {
let searchParam = request.nextUrl.searchParams.get('renderer');
const pathname: string = request.nextUrl.pathname;

// Merge all redirects into a single list
// The order of the list is important
// The first matching redirect will be used
const redirectList: RedirectData[] = [
...docsVersionsRedirects,
...docsRenderersRedirects,
...docsCommonRedirects,
];

for (const redirectData of redirectList) {
for (const redirectData of listOfRedirects) {
let sourcePattern = redirectData.source;
let destinationURL = redirectData.destination;

Expand Down
16 changes: 16 additions & 0 deletions apps/frontpage/redirects/redirects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { docsCommonRedirects } from './docs-common-redirects';
import { docsRenderersRedirects } from './docs-renderers-redirects';
import { docsVersionsRedirects } from './docs-versions-redirects';
import { redirectsTags } from './redirects_tags';
import { RedirectData } from './types';

// Merge all redirects into a single list
// The order of the list is important
// The first matching redirect will be used

export const listOfRedirects: RedirectData[] = [
...docsVersionsRedirects,
...docsRenderersRedirects,
...docsCommonRedirects,
...redirectsTags,
];
9 changes: 9 additions & 0 deletions apps/frontpage/redirects/redirects_tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { RedirectData } from './types';

export const redirectsTags: RedirectData[] = [
{
source: '/tag/:path',
destination: '/addons/tag/:path',
permanent: true,
},
];

0 comments on commit e7e8f78

Please sign in to comment.