Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add redirects for tags #161

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
];