diff --git a/data/notion_migration.yaml b/data/notion_migration.yaml index a4a025d9dfb5..12e8387c7baa 100644 --- a/data/notion_migration.yaml +++ b/data/notion_migration.yaml @@ -2,7 +2,7 @@ # - 'source': URL path to redirect, as currently visible on handbook.sourcegraph.com # - 'destination': New URL top direct to. If a public 'sourcegraph.notion.site' page is available, prefer that instead of the internal Notion URL. redirections: - - source: /departments/engineering/teams/devinfra + - source: /departments/engineering/teams/devinfra/ destination: https://sourcegraph.notion.site/Developer-Infrastructure-Team-a46433b93bb2445abc1966c93a570a26 # Core Services - source: /departments/engineering/teams/core-services/ diff --git a/src/scripts/generate-redirects.mjs b/src/scripts/generate-redirects.mjs index 6f887b314a95..dd413001a184 100644 --- a/src/scripts/generate-redirects.mjs +++ b/src/scripts/generate-redirects.mjs @@ -7,7 +7,7 @@ import fs from 'fs/promises' import redirects from './redirects.mjs' -const redirectLines = (await redirects()).map(({ source, destination }) => `${source} ${destination}`).join('\n') +const redirectLines = (await redirects()).map((entry) => `${entry.source} ${entry.destination}${entry.force ? ' 302!' : ''}`).join('\n') const lines = `\n# Generated by generate-redirects.mjs from Git history\n${redirectLines}\n` console.log('Redirects:\n', lines) diff --git a/src/scripts/redirects.mjs b/src/scripts/redirects.mjs index 36a2ac378211..26ec59f835a1 100644 --- a/src/scripts/redirects.mjs +++ b/src/scripts/redirects.mjs @@ -31,10 +31,21 @@ export function cleanupRedirects(movedPages) { /** * Reads Notion specific redirections from data/notion_migration.yaml. * - * @returns {redirections: {source: string, destination: string}[]} + * @returns {redirections: {source: string, destination: string, force: true}[]} */ async function readNotionMigrationRedirects() { - return load(await readFile('data/notion_migration.yaml', 'utf8')) + const data = load(await readFile('data/notion_migration.yaml', 'utf8')) + + // While NextJS is okay if content exists when setting up a redirection, + // Netlify doesn't: it will skip the redirection entirely if it finds + // existing content. + // To go around that, we add a new field 'force' that the script that + // generate the final _redirects file used by Netlify uses to append + // 301! on that entry, effectively forcing the redirection. + for ( const entry of data.redirections ) { + entry.force = true + } + return data } /** @@ -47,12 +58,10 @@ export default async function redirects() { const notionRedirections = await readNotionMigrationRedirects() return cleanupRedirects([ ...movedPages, - ...notionRedirections.redirections, - // Add custom redirects { source: '/careers', destination: 'https://about.sourcegraph.com/jobs', }, - ]) + ]).concat(notionRedirections.redirections) // we skip the cleanup because notion redirects are always going outside. }