diff --git a/docs/cody/capabilities/commands.mdx b/docs/cody/capabilities/prompts.mdx similarity index 100% rename from docs/cody/capabilities/commands.mdx rename to docs/cody/capabilities/prompts.mdx diff --git a/next.config.js b/next.config.js index 85bf27ef0..b521a8d58 100644 --- a/next.config.js +++ b/next.config.js @@ -14,36 +14,36 @@ const nextConfig = { // https://vercel.com/docs/projects/environment-variables/system-environment-variables // basePath: process.env.VERCEL_ENV === 'production' ? '/docs' : '', basePath: '/docs', - async redirects() { - return [ - ...updatedRedirectsData, - { - source: `/v/${config.DOCS_LATEST_VERSION}/:slug*`, - destination: `https://sourcegraph.com/docs/:slug*`, - permanent: false - }, - { - source: `/@${config.DOCS_LATEST_VERSION}/:slug*`, - destination: `https://sourcegraph.com/docs/:slug*`, - permanent: false - }, - { - source: '/v/:version(\\d+\\.\\d+)/:slug*', - destination: 'https://:version.sourcegraph.com/:slug*', - permanent: true - }, - { - source: '/@:version(\\d+\\.\\d+)/:slug*', - destination: 'https://:version.sourcegraph.com/:slug*', - permanent: true - }, - { - source: '/changelog.rss', - destination: '/technical-changelog.rss', - permanent: true - } - ]; - } + // async redirects() { + // return [ + // ...updatedRedirectsData, + // { + // source: `/v/${config.DOCS_LATEST_VERSION}/:slug*`, + // destination: `https://sourcegraph.com/docs/:slug*`, + // permanent: false + // }, + // { + // source: `/@${config.DOCS_LATEST_VERSION}/:slug*`, + // destination: `https://sourcegraph.com/docs/:slug*`, + // permanent: false + // }, + // { + // source: '/v/:version(\\d+\\.\\d+)/:slug*', + // destination: 'https://:version.sourcegraph.com/:slug*', + // permanent: true + // }, + // { + // source: '/@:version(\\d+\\.\\d+)/:slug*', + // destination: 'https://:version.sourcegraph.com/:slug*', + // permanent: true + // }, + // { + // source: '/changelog.rss', + // destination: '/technical-changelog.rss', + // permanent: true + // } + // ]; + // } }; module.exports = async () => { diff --git a/src/data/navigation.ts b/src/data/navigation.ts index fb8e6bd91..3f5e48333 100644 --- a/src/data/navigation.ts +++ b/src/data/navigation.ts @@ -55,7 +55,7 @@ export const navigation: NavigationItem[] = [ subsections: [ { title: "Chat", href: "/cody/capabilities/chat", }, { title: "Autocomplete", href: "/cody/capabilities/autocomplete", }, - { title: "Prompts", href: "/cody/capabilities/commands", }, + { title: "Prompts", href: "/cody/capabilities/prompts", }, { title: "OpenCtx", href: "/cody/capabilities/openctx", }, { title: "Debug Code", href: "/cody/capabilities/debug-code", }, { title: "Context Filters", href: "/cody/capabilities/ignore-context", }, diff --git a/src/data/redirects.ts b/src/data/redirects.ts index c6e331297..eeddb73bf 100644 --- a/src/data/redirects.ts +++ b/src/data/redirects.ts @@ -6717,6 +6717,20 @@ const redirectsData = [ destination: "/code-search/code-navigation/inference_configuration", permanent: true }, + // Model Config docs + { + source: "/cody/clients/model-configuration", + destination: "/cody/enterprise/model-configuration", + permanent: true + }, + + //Commands redirects + { + source: "/cody/capabilities/commands", + destination: "/cody/capabilities/prompts", + permanent: true + }, + ]; diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 000000000..ea508acda --- /dev/null +++ b/src/middleware.ts @@ -0,0 +1,88 @@ +import { NextResponse } from 'next/server' +import type { NextRequest } from 'next/server' +import docsConfig from '../docs.config.js' + +const { updatedRedirectsData } = require('./data/redirects.ts'); + +function createRedirectUrl(request: NextRequest, destination: string, path: string): string { + // Handle absolute URLs + if (destination.startsWith('http')) { + // Handle dynamic slug replacements + if (destination.includes(':slug')) { + const slugMatch = path.match(/[^/]+$/) + const slug = slugMatch ? slugMatch[0] : '' + destination = destination.replace(':slug*', slug) + } + // Handle version replacements + if (destination.includes(':version')) { + const versionMatch = path.match(/\d+\.\d+/) + const version = versionMatch ? versionMatch[0] : '' + destination = destination.replace(':version', version) + } + + return destination + } + + // Handle relative paths + const basePath = '/docs' + return destination.startsWith('/') ? + `${request.nextUrl.origin}${basePath}${destination}` : + `${request.nextUrl.origin}${basePath}/${destination}` +} + +export function middleware(request: NextRequest) { + const path = request.nextUrl.pathname + const pathWithoutBase = path.replace('/docs', '') + + // Handle base redirects from redirects.ts + const redirect = updatedRedirectsData.find((r: any) => r.source === pathWithoutBase) + if (redirect) { + return NextResponse.redirect(createRedirectUrl(request, redirect.destination, path)) + } + // Handle version without slug + const versionOnlyMatch = pathWithoutBase.match(/^\/v\/(\d+\.\d+)$/) + if (versionOnlyMatch) { + return NextResponse.redirect(`https://${versionOnlyMatch[1]}.sourcegraph.com/`) + } + // Handle version-specific redirects + if (pathWithoutBase.startsWith(`/v/${docsConfig.DOCS_LATEST_VERSION}/`)) { + return NextResponse.redirect(createRedirectUrl( + request, + `https://sourcegraph.com/docs/:slug*`, + pathWithoutBase + )) + } + if (pathWithoutBase.startsWith(`/@${docsConfig.DOCS_LATEST_VERSION}/`)) { + return NextResponse.redirect(createRedirectUrl( + request, + `https://sourcegraph.com/docs/:slug*`, + pathWithoutBase + )) + } + const versionMatch = pathWithoutBase.match(/^\/v\/(\d+\.\d+)\/(.*)/) + if (versionMatch) { + return NextResponse.redirect(createRedirectUrl( + request, + 'https://:version.sourcegraph.com/:slug*', + pathWithoutBase + )) + } + const atVersionMatch = pathWithoutBase.match(/^\/@(\d+\.\d+)\/(.*)/) + if (atVersionMatch) { + return NextResponse.redirect(createRedirectUrl( + request, + 'https://:version.sourcegraph.com/:slug*', + pathWithoutBase + )) + } + if (pathWithoutBase === '/changelog.rss') + return NextResponse.redirect(createRedirectUrl(request, '/technical-changelog.rss', path)) + + return NextResponse.next() +} + +export const config = { + matcher: [ + '/((?!api|_next/static|_next/image|assets|favicon.ico|sw.js).*)', + ], +}