From 7de5b4a349d1769261d6ec41ccac8400b0ecf17d Mon Sep 17 00:00:00 2001 From: Almeida Date: Tue, 7 Oct 2025 10:50:53 +0100 Subject: [PATCH] refactor: remove guide route prefix (#11146) * refactor: remove guide route prefix * chore: implement backwards compat redirect * Change guide redirect destination and permanence Updated the redirect destination and permanence for the guide route. --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- apps/guide/content/docs/legacy/meta.json | 6 +-- .../src/app/{guide => }/[[...slug]]/page.tsx | 6 +-- apps/guide/src/app/guide/layout.tsx | 42 ------------------ apps/guide/src/app/layout.tsx | 43 +++++++++++++++++-- .../app/{docs-og => og}/[...slug]/route.tsx | 2 +- apps/guide/src/app/page.tsx | 5 --- apps/guide/src/lib/source.ts | 2 +- apps/guide/src/middleware.ts | 16 +++++++ apps/website/next.config.ts | 4 +- 9 files changed, 66 insertions(+), 60 deletions(-) rename apps/guide/src/app/{guide => }/[[...slug]]/page.tsx (91%) delete mode 100644 apps/guide/src/app/guide/layout.tsx rename apps/guide/src/app/{docs-og => og}/[...slug]/route.tsx (89%) delete mode 100644 apps/guide/src/app/page.tsx create mode 100644 apps/guide/src/middleware.ts diff --git a/apps/guide/content/docs/legacy/meta.json b/apps/guide/content/docs/legacy/meta.json index 88b426f51..64c5aeb61 100644 --- a/apps/guide/content/docs/legacy/meta.json +++ b/apps/guide/content/docs/legacy/meta.json @@ -1,9 +1,9 @@ { "pages": [ - "[MessageCircleQuestion][FAQ](/guide/legacy/popular-topics/faq)", - "[ArrowDownToLine][Updating to v14](/guide/legacy/additional-info/changes-in-v14)", + "[MessageCircleQuestion][FAQ](/legacy/popular-topics/faq)", + "[ArrowDownToLine][Updating to v14](/legacy/additional-info/changes-in-v14)", "[LibraryBig][Documentation](https://discord.js.org/docs)", - "[Info][Introduction](/guide/legacy)", + "[Info][Introduction](/legacy)", "---Setup---", "preparations", "---Your App---", diff --git a/apps/guide/src/app/guide/[[...slug]]/page.tsx b/apps/guide/src/app/[[...slug]]/page.tsx similarity index 91% rename from apps/guide/src/app/guide/[[...slug]]/page.tsx rename to apps/guide/src/app/[[...slug]]/page.tsx index 27c566e85..a43e90e9a 100644 --- a/apps/guide/src/app/guide/[[...slug]]/page.tsx +++ b/apps/guide/src/app/[[...slug]]/page.tsx @@ -8,7 +8,7 @@ export async function generateStaticParams() { return source.generateParams(); } -export async function generateMetadata(props: { params: Promise<{ slug?: string[] }> }) { +export async function generateMetadata(props: { params: Promise<{ slug?: string[] }> }): Promise { const params = await props.params; const page = source.getPage(params.slug); @@ -16,7 +16,7 @@ export async function generateMetadata(props: { params: Promise<{ slug?: string[ notFound(); } - const image = ['/docs-og', ...(params.slug ?? []), 'image.png'].join('/'); + const image = ['/og', ...(params.slug ?? []), 'image.png'].join('/'); return { title: page.data.title, description: page.data.description, @@ -27,7 +27,7 @@ export async function generateMetadata(props: { params: Promise<{ slug?: string[ card: 'summary_large_image', images: image, }, - } satisfies Metadata; + }; } export default async function Page(props: { readonly params: Promise<{ slug?: string[] }> }) { diff --git a/apps/guide/src/app/guide/layout.tsx b/apps/guide/src/app/guide/layout.tsx deleted file mode 100644 index dab30f0a7..000000000 --- a/apps/guide/src/app/guide/layout.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import { DocsLayout } from 'fumadocs-ui/layouts/docs'; -import type { CSSProperties, ReactNode } from 'react'; -import { baseOptions } from '@/app/layout.config'; -import { source } from '@/lib/source'; - -export default function Layout({ children }: { readonly children: ReactNode }) { - return ( - - {node.icon} - - ), - }; - }, - }, - }} - tree={source.pageTree} - {...baseOptions} - > - {children} - - ); -} diff --git a/apps/guide/src/app/layout.tsx b/apps/guide/src/app/layout.tsx index d71586d0a..23dfe10d3 100644 --- a/apps/guide/src/app/layout.tsx +++ b/apps/guide/src/app/layout.tsx @@ -1,11 +1,14 @@ import { Analytics } from '@vercel/analytics/react'; +import { DocsLayout } from 'fumadocs-ui/layouts/docs'; import { RootProvider } from 'fumadocs-ui/provider'; import { GeistMono } from 'geist/font/mono'; import { GeistSans } from 'geist/font/sans'; import type { Metadata, Viewport } from 'next'; -import type { PropsWithChildren } from 'react'; +import type { CSSProperties, PropsWithChildren } from 'react'; import { Body } from '@/app/layout.client'; +import { source } from '@/lib/source'; import { ENV } from '@/util/env'; +import { baseOptions } from './layout.config'; import '@/styles/base.css'; @@ -18,7 +21,7 @@ export const viewport: Viewport = { }; export const metadata: Metadata = { - metadataBase: new URL(ENV.IS_LOCAL_DEV ? `http://localhost:${ENV.PORT}` : 'https://next.discordjs.guide'), + metadataBase: new URL(ENV.IS_LOCAL_DEV ? `http://localhost:${ENV.PORT}` : 'https://discordjs.guide'), title: { template: '%s | discord.js', default: 'discord.js', @@ -74,7 +77,41 @@ export default async function RootLayout({ children }: PropsWithChildren) { return ( - {children} + + + {node.icon} + + ), + }; + }, + }, + }} + tree={source.pageTree} + {...baseOptions} + > + {children} + + diff --git a/apps/guide/src/app/docs-og/[...slug]/route.tsx b/apps/guide/src/app/og/[...slug]/route.tsx similarity index 89% rename from apps/guide/src/app/docs-og/[...slug]/route.tsx rename to apps/guide/src/app/og/[...slug]/route.tsx index f09477324..15c636617 100644 --- a/apps/guide/src/app/docs-og/[...slug]/route.tsx +++ b/apps/guide/src/app/og/[...slug]/route.tsx @@ -12,7 +12,7 @@ export function generateStaticParams() { export async function GET(_req: Request, { params }: { params: Promise<{ slug: string[] }> }) { const { slug } = await params; const page = source.getPage(slug.slice(0, -1)); - // const fontData = await fetch(new URL('../../../assets/Geist-Regular.ttf', import.meta.url), { + // const fontData = await fetch(new URL('../../assets/Geist-Regular.ttf', import.meta.url), { // next: { revalidate: 604_800 }, // }).then(async (res) => res.arrayBuffer()); diff --git a/apps/guide/src/app/page.tsx b/apps/guide/src/app/page.tsx deleted file mode 100644 index d8ac2a41e..000000000 --- a/apps/guide/src/app/page.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { redirect } from 'next/navigation'; - -export default async function Page() { - redirect('/guide/legacy'); -} diff --git a/apps/guide/src/lib/source.ts b/apps/guide/src/lib/source.ts index d67be3e47..be59f8d79 100644 --- a/apps/guide/src/lib/source.ts +++ b/apps/guide/src/lib/source.ts @@ -15,6 +15,6 @@ export const source = loader({ return undefined; }, - baseUrl: '/guide/', + baseUrl: '/', source: docs.toFumadocsSource(), }); diff --git a/apps/guide/src/middleware.ts b/apps/guide/src/middleware.ts new file mode 100644 index 000000000..5b1ad2aad --- /dev/null +++ b/apps/guide/src/middleware.ts @@ -0,0 +1,16 @@ +import { NextResponse, type NextRequest } from 'next/server'; + +export function middleware(request: NextRequest) { + // TODO: Remove this eventually + if (request.nextUrl.pathname.startsWith('/guide/')) { + const newUrl = request.nextUrl.clone(); + newUrl.pathname = newUrl.pathname.replace('/guide/', '/'); + return NextResponse.redirect(new URL(newUrl.pathname, request.url)); + } + + return NextResponse.redirect(new URL('/legacy', request.url)); +} + +export const config = { + matcher: ['/', '/guide/:path*'], +}; diff --git a/apps/website/next.config.ts b/apps/website/next.config.ts index 334cd5cb9..f628b3023 100644 --- a/apps/website/next.config.ts +++ b/apps/website/next.config.ts @@ -39,8 +39,8 @@ export default { }, { source: '/guide/:path*', - destination: 'https://next.discordjs.guide/guide/:path*', - permanent: true, + destination: 'https://discordjs.guide/:path*', + permanent: false, }, ]; },