diff --git a/docs/admin/auth/index.mdx b/docs/admin/auth/index.mdx index 5a8393b6e..7bce17bf7 100644 --- a/docs/admin/auth/index.mdx +++ b/docs/admin/auth/index.mdx @@ -533,9 +533,3 @@ Usernames from authentication providers are normalized before being used in Sour For example, a user whose external username (according the authentication provider) is `alice_smith@example.com` would have the Sourcegraph username `alice-smith`. If multiple accounts normalize into the same username, separate accounts are still created, but Sourcegraph will add a randomized suffix to the username to ensure uniqueness. - -## Remind users to connect external accounts - -When authorization is activated, users must link their external code host accounts with their Sourcegraph accounts to access private repositories. -To ensure users are aware of any unlinked accounts, enable the external-accounts-modal feature flag. -This prompts users to connect any missing external accounts upon visiting Sourcegraph. diff --git a/docs/admin/deploy/docker-compose/aws.mdx b/docs/admin/deploy/docker-compose/aws.mdx index d59e2a818..e11264a0f 100644 --- a/docs/admin/deploy/docker-compose/aws.mdx +++ b/docs/admin/deploy/docker-compose/aws.mdx @@ -1,13 +1,7 @@ # Install Sourcegraph on Amazon Web Services (AWS) -> ⚠️ We recommend new users use our [AWS AMI](/admin/deploy/machine-images/aws-oneclick) or [script-install](/admin/deploy/single-node/script) instructions, which are easier and offer more flexibility when configuring Sourcegraph. Existing customers can reach out to our Customer Engineering team support@sourcegraph.com if they wish to migrate to these deployment models. - - - This guide will take you through how to deploy Sourcegraph with [Docker Compose](https://docs.docker.com/compose/) to a single EC2 instance on Amazon Web Services (AWS). -Deploy a Sourcegraph instance with an [AWS AMI](/admin/deploy/machine-images/aws-ami) or [AWS One-Click](/admin/deploy/machine-images/aws-oneclick). (Recommended) - ## Configure diff --git a/docs/admin/deploy/docker-compose/azure.mdx b/docs/admin/deploy/docker-compose/azure.mdx index ad1230e73..f30d1c7e4 100644 --- a/docs/admin/deploy/docker-compose/azure.mdx +++ b/docs/admin/deploy/docker-compose/azure.mdx @@ -1,7 +1,5 @@ # Install Sourcegraph on Azure -> ⚠️ We recommend new users use our [machine image](/admin/deploy/machine-images/) or [script-install](/admin/deploy/single-node/script) instructions, which are easier and offer more flexibility when configuring Sourcegraph. Existing customers can reach out to our Customer Engineering team support@sourcegraph.com if they wish to migrate to these deployment models. - This guide will take you through how to set up a Sourcegraph instance on an Azure virtual machine with [Docker Compose](https://docs.docker.com/compose/). diff --git a/docs/admin/deploy/docker-compose/digitalocean.mdx b/docs/admin/deploy/docker-compose/digitalocean.mdx index 5027eadbd..66096d1ad 100644 --- a/docs/admin/deploy/docker-compose/digitalocean.mdx +++ b/docs/admin/deploy/docker-compose/digitalocean.mdx @@ -1,7 +1,5 @@ # Install Sourcegraph on DigitalOcean -> ⚠️ We recommend new users use our [machine image](/admin/deploy/machine-images/) or [script-install](/admin/deploy/single-node/script) instructions, which are easier and offer more flexibility when configuring Sourcegraph. Existing customers can reach out to our Customer Engineering team support@sourcegraph.com if they wish to migrate to these deployment models. - --- This guide will take you through how to deploy a Sourcegraph instance to a single DigitalOcean Droplet with [Docker Compose](https://docs.docker.com/compose/). diff --git a/docs/admin/deploy/docker-compose/google_cloud.mdx b/docs/admin/deploy/docker-compose/google_cloud.mdx index b83d74962..f0bd60ed8 100644 --- a/docs/admin/deploy/docker-compose/google_cloud.mdx +++ b/docs/admin/deploy/docker-compose/google_cloud.mdx @@ -1,7 +1,5 @@ # Install Sourcegraph on Google Cloud -> ⚠️ We recommend new users use our [GCE machine image](/admin/deploy/machine-images/gce) or [script-install](/admin/deploy/single-node/script) instructions, which are easier and offer more flexibility when configuring Sourcegraph. Existing customers can reach out to our Customer Engineering team support@sourcegraph.com if they wish to migrate to these deployment models. - This guide will take you through how to deploy Sourcegraph with [Docker Compose](https://docs.docker.com/compose/) to a single node running on Google Cloud. ## Configure diff --git a/docs/admin/deploy/index.mdx b/docs/admin/deploy/index.mdx index e79d6900c..abe94deb2 100644 --- a/docs/admin/deploy/index.mdx +++ b/docs/admin/deploy/index.mdx @@ -49,7 +49,7 @@ Single-node, self hosted solution for enterprises looking for a simpler, non-Kub Best for enterprises looking for a self-hosted solution on the Cloud provider of their choice. -Customized machine images allow you to spin up a preconfigured Sourcegraph instance with just a few clicks, all in less than 10 minutes. Currently available in the following hosts: +Machine images provide a preconfigured Sourcegraph instance that can be deployed in minutes with minimal effort. While they offer simplicity, they are designed as a standardized solution and do not support customization. Currently available on the following hosts: diff --git a/docs/admin/deploy/machine-images/aws-oneclick.mdx b/docs/admin/deploy/machine-images/aws-oneclick.mdx index f5556017e..2d10a4290 100644 --- a/docs/admin/deploy/machine-images/aws-oneclick.mdx +++ b/docs/admin/deploy/machine-images/aws-oneclick.mdx @@ -2,7 +2,7 @@ This page describes how to launch a verified and pre-configured Sourcegraph instance in just ~10 minutes using our one-click CloudFormation template and standard AMIs. -Prefer manually installing on AWS yourself? See our [AMI](/admin/deploy/machine-images/aws-ami) installation options or our [script-install](/admin/deploy/single-node/script) installation options. +Prefer manually installing on AWS yourself? See our [AMI](/admin/deploy/machine-images/aws-ami) installation options. ## Prerequisites diff --git a/docs/admin/postgres.mdx b/docs/admin/postgres.mdx index e52110eff..021d4ec0a 100644 --- a/docs/admin/postgres.mdx +++ b/docs/admin/postgres.mdx @@ -56,7 +56,7 @@ When running an [external PostgreSQL instance](/admin/external_services/postgres - [Heroku](https://devcenter.heroku.com/articles/upgrading-heroku-postgres-databases) - [EnterpriseDB](https://www.enterprisedb.com/docs/en/9.6/pg/upgrading.html) - [Citus](http://docs.citusdata.com/en/v8.1/admin_guide/upgrading_citus.html) - - [Aiven PostgreSQL](https://help.aiven.io/postgresql/operations/how-to-perform-a-postgresql-in-place-major-version-upgrade) + - [Aiven PostgreSQL](https://aiven.io/docs/platform/concepts/maintenance-window#related-pages) - [Your own PostgreSQL](https://www.postgresql.org/docs/16/pgupgrade.html) 4. Turn Sourcegraph back on connecting to the now-upgraded database. diff --git a/docs/admin/pricing.mdx b/docs/admin/pricing.mdx index 1f91442b5..5d539c874 100644 --- a/docs/admin/pricing.mdx +++ b/docs/admin/pricing.mdx @@ -48,4 +48,4 @@ A billable active Code Search or Code Intelligence Platform user is one who is s A user who has accessed a Sourcegraph product is counted as active once they complete an action that represents usage reflected above. -User counts can be found in the **Site admin** section of the Sourcegraph web application, and Cody-specific usage metrics can be found in the [Cody Analytics service](../cody/clients/enable-cody-enterprise#analytics). +User counts and more usage metrics can be found in [Sourcegraph Analytics](../analytics). diff --git a/docs/analytics/cloud.mdx b/docs/analytics/cloud.mdx new file mode 100644 index 000000000..aba096ad8 --- /dev/null +++ b/docs/analytics/cloud.mdx @@ -0,0 +1,18 @@ +# Sourcegraph Cloud Analytics + +The following instructions are for all Sourcegraph Cloud and self-hosted customers who have upgraded to a sufficient version of Sourcegraph (5.9+) and fully enabled usage telemetry. Customers that self-host can also view our [self-hosted analytics enablement](/self-hosted). + +![Sourcegraph-cloud-analytics](https://storage.googleapis.com/sourcegraph-assets/cloud-analytics.png) + +## Enablement instructions + +To enable Sourcegraph Analytics: + +- Create an account on [Sourcegraph Accounts](https://accounts.sourcegraph.com/), or find the email address associated with your existing account. +- Contact your Sourcegraph Technical Advisor or point of contact (or email us at support@sourcegraph.com if you don't know your contact), provide them with the email address you used to register above and ask for access to Sourcegraph Analytics. +- They will validate your account and link it to your Sourcegraph Enterprise instance's usage metrics. +- Sign in to [Sourcegraph Analytics](https://cody-analytics.sourcegraph.com). + +## Data export + +Sourcegraph Cloud Analytics also includes a CSV export option with key metrics like the number of searches, chats, autocomplete suggestions, completion acceptance rate (CAR %), and more. The data is split by user, day, client/editor, and programming language, perfect for automating retrieval and analyzing data in ways that make the most sense to your organization. diff --git a/docs/analytics/index.mdx b/docs/analytics/index.mdx new file mode 100644 index 000000000..8f33247a7 --- /dev/null +++ b/docs/analytics/index.mdx @@ -0,0 +1,101 @@ +# Sourcegraph Analytics + +Enterprise customers can use Sourcegraph Analytics to get a clear view of usage, engagement, performance, and impact. + +## Sourcegraph Cloud Analytics + +[Sourcegraph Cloud](/cloud) customers can use our managed [cloud analytics service](https://cody-analytics.sourcegraph.com) for Cody and Code Search usage data. +Self-hosted customers can also use this service, but they must + +Upgrade to a supported version of Sourcegraph (5.9+) +Have fully enabled usage telemetry. +- [Enablement instructions](/analytics/cloud#enablement) + +![Sourcegraph-cloud-analytics](https://storage.googleapis.com/sourcegraph-assets/cloud-analytics.png) + +## Self-Hosted Analytics + +Self-hosted customers will soon be able to use our self-hosted and locally deployed analytics service, built on Grafana, to see Sourcegraph usage data. + +This product is in development now. If you would like to learn more, please contact your Sourcegraph representative. + +## Metrics + +We provide a set of metrics that can be used to monitor Sourcegraph usage, engagement, performance, and impact within your enterprise. + +Learn more about how we think about [the ROI of Sourcegraph in our blog](https://sourcegraph.com/blog/measuring-the-impact-of-ai-coding-tools). + +### User metrics available + +| Metric | Description | +| --------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | +| Total active users | Total number of unique users who have used any Sourcegraph product during the selected time | +| Average daily users | The average number of unique users who use Sourcegraph per day during the selected time | +| Average days of activity per user | The average number of days each user actively uses Sourcegraph during the selected time | +| Daily active users | Number of unique users who used Sourcegraph by day | +| Weekly active users | Number of unique users who used Sourcegraph by week | +| Daily users by product | Count of daily users across different Sourcegraph products (Cody, Code Search, Code Insights, etc.) | +| Product usage distribution (by percentage of users) | Percentage breakdown of users across different Sourcegraph product groupings during the selected time | +| Detailed user activity (top 20 users) | List of the 20 most active users during the selected time and their usage patterns | +| Frequency of usage | Count of users who used Sourcegraph _n_ times over the past 30 days | + +Cody-only user metrics + +Many of the metrics above are also available for Cody only. However, some user definitions are slightly different: + +| User category | Description | +| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Authenticated users | All users signed in to Cody in an editor or interacted with Cody on the web during the selected period. [Read more](/admin/pricing#authenticated-users). | +| Active users | All users who sign in to Cody in an editor or interact with Cody on the web during the period selected. [Read more](/admin/pricing#billable-active-users). | + +### Code Search & navigation metrics + +| Metric | Description | +| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | +| Total in-product searchers | Number of unique users who performed searches using the Sourcegraph search interface during the selected time | +| Total result clicks | Count of times users clicked on search results to view files or other resources during the selected time | +| Total file views | Number of times users viewed individual files through Sourcegraph during the selected time | +| Daily in-product search activity | Count of search operations performed each day through the Sourcegraph interface | +| Daily search users (in-product and API) | Number of unique users performing searches each day, including both UI and API usage | +| All searches (in-product and API) by type | Breakdown of searches by category (e.g., literal, regex), including both UI and API usage | +| Total code navigation actions | Count of all code navigation operations performed (e.g., go-to-definition, find references) during the selected time period | +| Precise code navigation % | Percentage of code navigation actions that used precise intelligence rather than search-based results during the selected time | +| Daily code navigation activity | Count of code navigation operations performed each day | +| Daily code navigation users | Number of unique users utilizing code navigation features each day | +| Precise vs. search-based code navigation actions by language | Comparison of precise vs. search-based navigation success rates broken down by programming language | + +### Autocompletion metrics + +| Metric | Description | +| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Total accepted completions | Count of completions accepted by users during the selected time | +| Hours saved | The number of hours saved by Cody users, assuming 2 minutes saved per completion | +| Completions by day | The number of completions suggested by day and by editor. | +| Completion acceptance rate (CAR) | The percent of completions presented to a user for at least 750ms accepted by day, the editor, day, and month. | +| Weighted completion acceptance rate (wCAR) | Similar to CAR, but weighted by the number of characters presented in the completion, and only counting those fully retained by the user for X minutes after accepting the completion, by the editor, day, and month. | +| Average completion latency (ms) | The average milliseconds of latency before a user is presented with a completion suggestion by an editor. | +| Acceptance rate by language | CAR and total completion suggestions broken down by editor during the selected time | + +### Chat and prompt metrics + +| Metric | Description | +| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | +| Total chat events | Total number of chat interactions with Cody during the selected time | +| Minutes saved per chat | Average time saved per chat interaction with Cody during the selected time | +| Hours saved by chats | Total hours saved through Cody chat interactions during the selected time , assuming 5 minutes saved per chat | +| Cody chats by day | Daily count of chat interactions | +| Cody chat users | Daily count of chat users | +| Prompts created, edited, and deleted by day | Daily count of prompt management activities, including creation, modification, and removal | +| Users creating, editing, and deleting prompts by day | Number of unique users performing prompt management activities each day | + +### Command metrics (deprecated) + +_As of Sourcegraph version 5.10, commands are being deprecated in favor of our new feature, chat prompts. As a result, if your Sourcegraph instance is running version 5.10 or later, you may see decreased command usage. In the coming weeks, these command metrics will be deprecated and replaced with new prompt metrics on the Chats tab._ + +| Metric | Description | +| ----------------------- | ----------------------------------------------------------------------------------------------------------- | +| Total command events | Total number of command executions during the selected time | +| Hours saved by commands | Total hours saved through command executions during the selected time, assuming 5 minutes saved per command | +| Cody commands by day | Daily count of command executions | +| Cody command users | Daily count of command users | +| Most used commands | Ranking of most frequently used Cody commands during the selected time | diff --git a/docs/analytics/self-hosted.mdx b/docs/analytics/self-hosted.mdx new file mode 100644 index 000000000..d067ead0c --- /dev/null +++ b/docs/analytics/self-hosted.mdx @@ -0,0 +1,19 @@ +# Sourcegraph Self-Hosted Analytics + +This feature is not yet available. Coming soon. + +Sourcegraph Self-Hosted Analytics is coming soon! Self-hosted customers can view usage metrics in a locally deployed analytics service built on Grafana. + +This product is in development now. If you would like to learn more, please contact your Sourcegraph representative. + +## Set-up instructions + +Coming soon. + +## Updates + +Coming soon. + +## Custom metrics + +Coming soon. diff --git a/docs/technical-changelog.mdx b/docs/technical-changelog.mdx index 63a71d1f4..20c3284cf 100644 --- a/docs/technical-changelog.mdx +++ b/docs/technical-changelog.mdx @@ -6,6 +6,11 @@ This page documents all notable changes to Sourcegraph. For more detailed change # 5.11 Patch 5 +> Attention - If upgrading from Sourcegraph version 5.9 or earlier, this release will update our included database container images from Postgres 12 to Postgres 16. +> Customers are advised to have a database backup before upgrading. See our [postgres 12 end of life](https://sourcegraph.com/docs/admin/postgres12_end_of_life_notice#postgres-12-end-of-life) notice for more information. +> +> Also be sure to check your deployment type's [upgrade notes](http://sourcegraph.com/docs/admin/updates#instance-specific-procedures)! + ## v5.11.6271 - [sourcegraph](https://github.com/sourcegraph/sourcegraph/releases/tag/v5.11.6271) @@ -35,6 +40,11 @@ This page documents all notable changes to Sourcegraph. For more detailed change # 5.11 Patch 4 +> Attention - If upgrading from Sourcegraph version 5.9 or earlier, this release will update our included database container images from Postgres 12 to Postgres 16. +> Customers are advised to have a database backup before upgrading. See our [postgres 12 end of life](https://sourcegraph.com/docs/admin/postgres12_end_of_life_notice#postgres-12-end-of-life) notice for more information. +> +> Also be sure to check your deployment type's [upgrade notes](http://sourcegraph.com/docs/admin/updates#instance-specific-procedures)! + ## v5.11.5234 - [sourcegraph](https://github.com/sourcegraph/sourcegraph/releases/tag/v5.11.5234) @@ -73,6 +83,11 @@ This page documents all notable changes to Sourcegraph. For more detailed change # 5.11 Patch 3 +> Attention - If upgrading from Sourcegraph version 5.9 or earlier, this release will update our included database container images from Postgres 12 to Postgres 16. +> Customers are advised to have a database backup before upgrading. See our [postgres 12 end of life](https://sourcegraph.com/docs/admin/postgres12_end_of_life_notice#postgres-12-end-of-life) notice for more information. +> +> Also be sure to check your deployment type's [upgrade notes](http://sourcegraph.com/docs/admin/updates#instance-specific-procedures)! + ## v5.11.4013 - [sourcegraph](https://github.com/sourcegraph/sourcegraph/releases/tag/v5.11.4013) @@ -120,6 +135,11 @@ This page documents all notable changes to Sourcegraph. For more detailed change # 5.11 Patch 2 +> Attention - If upgrading from Sourcegraph version 5.9 or earlier, this release will update our included database container images from Postgres 12 to Postgres 16. +> Customers are advised to have a database backup before upgrading. See our [postgres 12 end of life](https://sourcegraph.com/docs/admin/postgres12_end_of_life_notice#postgres-12-end-of-life) notice for more information. +> +> Also be sure to check your deployment type's [upgrade notes](http://sourcegraph.com/docs/admin/updates#instance-specific-procedures)! + ## v5.11.3601 - [sourcegraph](https://github.com/sourcegraph/sourcegraph/releases/tag/v5.11.3601) @@ -145,6 +165,11 @@ This page documents all notable changes to Sourcegraph. For more detailed change # 5.11 Patch 1 +> Attention - If upgrading from Sourcegraph version 5.9 or earlier, this release will update our included database container images from Postgres 12 to Postgres 16. +> Customers are advised to have a database backup before upgrading. See our [postgres 12 end of life](https://sourcegraph.com/docs/admin/postgres12_end_of_life_notice#postgres-12-end-of-life) notice for more information. +> +> Also be sure to check your deployment type's [upgrade notes](http://sourcegraph.com/docs/admin/updates#instance-specific-procedures)! + ## v5.11.2732 - [sourcegraph](https://github.com/sourcegraph/sourcegraph/releases/tag/v5.11.2732) @@ -178,7 +203,8 @@ This page documents all notable changes to Sourcegraph. For more detailed change # 5.11 Patch 0 -> Warning: This release updates the database container images from Postgres 12 to Postgres 16, and begins using Wolfi based images. Customers are advised to have a database backup before upgrading! See our [postgres 12 end of life](https://sourcegraph.com/docs/admin/postgres12_end_of_life_notice#postgres-12-end-of-life) notice! +> Attention - If upgrading from Sourcegraph version 5.9 or earlier, this release will update our included database container images from Postgres 12 to Postgres 16. +> Customers are advised to have a database backup before upgrading. See our [postgres 12 end of life](https://sourcegraph.com/docs/admin/postgres12_end_of_life_notice#postgres-12-end-of-life) notice for more information. > > Also be sure to check your deployment type's [upgrade notes](http://sourcegraph.com/docs/admin/updates#instance-specific-procedures)! diff --git a/src/data/navigation.ts b/src/data/navigation.ts index d01a75831..3e19aa4d1 100644 --- a/src/data/navigation.ts +++ b/src/data/navigation.ts @@ -256,6 +256,15 @@ export const navigation: NavigationItem[] = [ { title: "Pricing", href: "/admin/pricing" }, ], }, + { + title: "Sourcegraph Analytics", + href: "/analytics", + sections: [ + { title: "Metrics", href: "/analytics#metrics" }, + { title: "Cloud Analytics", href: "/analytics/cloud" }, + { title: "Self-hosted Analytics", href: "/analytics/self-hosted" }, + ], + }, { title: "Sourcegraph Cloud", href: "/cloud", diff --git a/src/middleware.ts b/src/middleware.ts index ea508acda..9c237a9e8 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -1,88 +1,141 @@ -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}` -} +import type { NextRequest } from 'next/server'; +import { NextResponse } 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')) { + // Extract version and full path after version + const versionMatch = path.match(/(?:\/v\/|@)(\d+\.\d+)\/(.*)/); + + if (versionMatch) { + const version = versionMatch[1]; + const remainingPath = versionMatch[2]; + + // Find matching redirect for the remaining path + const redirect = updatedRedirectsData.find( + (r: any) => + r.source === `/${remainingPath}` || + r.source === remainingPath + ); + + // If redirect exists, use its destination, otherwise use the remaining path + const finalPath = redirect + ? redirect.destination.replace(/^\//, '') + : remainingPath; + + // Replace placeholders and construct final URL + return destination + .replace(':version', version) + .replace(':slug*', finalPath); + } + + // Handle other cases as before + if (destination.includes(':slug')) { + const slugMatch = path.match(/[^/]+$/); + const slug = slugMatch ? slugMatch[0] : ''; + destination = destination.replace(':slug*', slug); + } + + 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() + 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 latest version without path - redirect to main docs + const latestVersionOnlyMatch = pathWithoutBase.match( + `^\/(?:v\/|@)${docsConfig.DOCS_LATEST_VERSION}\/?$` + ); + if (latestVersionOnlyMatch) { + return NextResponse.redirect(`https://sourcegraph.com/docs`); + } + + // Handle version without slug - both /v/X.Y and @X.Y formats (for non-latest versions) + const versionOnlyMatch = pathWithoutBase.match( + /^\/(?:v\/|@)(\d+\.\d+)\/?$/ + ); + if ( + versionOnlyMatch && + versionOnlyMatch[1] !== docsConfig.DOCS_LATEST_VERSION + ) { + 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).*)', - ], -} + matcher: ['/((?!api|_next/static|_next/image|assets|favicon.ico|sw.js).*)'] +};