diff --git a/gatsby-node.ts b/gatsby-node.ts index 0833710e4c..8418c6b004 100644 --- a/gatsby-node.ts +++ b/gatsby-node.ts @@ -4,6 +4,7 @@ import { glob } from "glob" import { updateCodeData } from "./scripts/update-code-data/update-code-data" import { organizeCodeData } from "./scripts/update-code-data/organize-code-data" import { sortCodeData } from "./scripts/update-code-data/sort-code-data" +import redirects from "./redirects.json" export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"] = async ({ actions }) => { @@ -128,6 +129,15 @@ export const createPages: GatsbyNode["createPages"] = async ({ statusCode: 200, }) + // legacy 301 redirects from previous iterations of the site + redirects.forEach(({ from, to }) => { + createRedirect({ + fromPath: from, + toPath: to, + statusCode: 301, + }) + }) + const result = await graphql(` query allMarkdownRemark { allMarkdownRemark { diff --git a/redirects.json b/redirects.json new file mode 100644 index 0000000000..64c293d581 --- /dev/null +++ b/redirects.json @@ -0,0 +1,66 @@ +[ + { + "from": "/docs/api-reference-errors", + "to": "/graphql-js/error/" + }, + { + "from": "/docs/api-reference-execution", + "to": "/graphql-js/execution/" + }, + { + "from": "/docs/api-reference-express-graphql", + "to": "/graphql-js/express-graphql/" + }, + { + "from": "/docs/api-reference-graphql", + "to": "/graphql-js/graphql/" + }, + { + "from": "/docs/api-reference-language", + "to": "/graphql-js/language/" + }, + { + "from": "/docs/api-reference-type-system", + "to": "/graphql-js/type/" + }, + { + "from": "/docs/api-reference-type-utilities", + "to": "/graphql-js/utilities/" + }, + { + "from": "/docs/api-reference-type-validation", + "to": "/graphql-js/validation/" + }, + { + "from": "/docs/getting-started", + "to": "/learn/" + }, + { + "from": "/docs/intro", + "to": "/learn/" + }, + { + "from": "/docs/introspection", + "to": "/learn/introspection/" + }, + { + "from": "/docs/queries", + "to": "/learn/queries/" + }, + { + "from": "/docs/typesystem", + "to": "/learn/schema/" + }, + { + "from": "/docs/validation", + "to": "/learn/validation/" + }, + { + "from": "/docs/videos", + "to": "/community/#videos/" + }, + { + "from": "/help", + "to": "/community/" + } +] diff --git a/static/_redirects b/static/_redirects deleted file mode 100644 index ca92c9f573..0000000000 --- a/static/_redirects +++ /dev/null @@ -1,25 +0,0 @@ -# 200 = reverse proxy rules -# https://www.netlify.com/docs/redirects/#rewrites-and-proxying - -/swapi-graphql https://graphql.github.io/swapi-graphql/ 200 -/swapi-graphql/* https://graphql.github.io/swapi-graphql/:splat 200 - -# 301 = permanent redirects -# https://www.netlify.com/docs/redirects/#http-status-codes - -/docs/api-reference-errors /graphql-js/error/ 301 -/docs/api-reference-execution /graphql-js/execution/ 301 -/docs/api-reference-express-graphql /graphql-js/express-graphql/ 301 -/docs/api-reference-graphql /graphql-js/graphql/ 301 -/docs/api-reference-language /graphql-js/language/ 301 -/docs/api-reference-type-system /graphql-js/type/ 301 -/docs/api-reference-type-utilities /graphql-js/utilities/ 301 -/docs/api-reference-type-validation /graphql-js/validation/ 301 -/docs/getting-started /learn/ 301 -/docs/intro /learn/ 301 -/docs/introspection /learn/introspection/ 301 -/docs/queries /learn/queries/ 301 -/docs/typesystem /learn/schema/ 301 -/docs/validation /learn/validation/ 301 -/docs/videos /community/#videos 301 -/help /community/ 301