diff --git a/website/config/conf.d/default.conf b/website/config/conf.d/default.conf index 5a3740a0e46..c3de4695959 100644 --- a/website/config/conf.d/default.conf +++ b/website/config/conf.d/default.conf @@ -5,6 +5,123 @@ server { error_page 404 /404/index.html; location / { - try_files $uri $uri/ =404; + rewrite ^/banana-cake-pop/?$ /products/bananacakepop permanent; + rewrite ^/company/?$ / permanent; + rewrite ^/products/?$ / permanent; + rewrite ^/services/?$ /services/support permanent; + rewrite ^/support/?$ /services/support permanent; + + # fixed year in already published blog post + rewrite ^/blog/2019/03/18/entity-framework/?$ /blog/2020/03/18/entity-framework permanent; + } + + location /docs { + set $latest v12; + set $hc /docs/hotchocolate/$latest; + + # docs -> hotchocolate + rewrite ^/docs/?$ $hc permanent; + + # marshmallowpie -> hotchocolate + rewrite ^/docs/marshmallowpie.*$ $hc permanent; + + # ensures version for hc & sbs is always set + rewrite ^/docs/(hotchocolate|strawberryshake)(?!/v\d+$|/v\d+/.*)(/.*)$ /docs/$1/$latest$2 permanent; + + # ensures version for bcp is always set + rewrite ^/docs/(bananacakepop)(?!/v\d+$|/v\d+\/.*)(/.*)$ /docs/$1/v2$2 permanent; + + # get-started -> get-started-with-graphql-in-net-core + rewrite ^/docs/hotchocolate/(v12|v13)/get-started/?$ /docs/hotchocolate/$1/get-started-with-graphql-in-net-core permanent; + + # code-first|schema|schema-first -> defining-a-schema + rewrite ^/docs/hotchocolate/(v12|v13)/(code-first|schema|schema-first)/?$ /docs/hotchocolate/$1/defining-a-schema permanent; + + # schema/custom-scalar-types -> defining-a-schema/scalars + rewrite ^/docs/hotchocolate/(v12|v13)/schema/custom-scalar-types/?$ /docs/hotchocolate/$1/defining-a-schema/scalars permanent; + + # schema/descriptions -> defining-a-schema/documentation + rewrite ^/docs/hotchocolate/(v12|v13)/schema/descriptions/?$ /docs/hotchocolate/$1/defining-a-schema/documentation permanent; + + # schema/directives -> defining-a-schema/directives + rewrite ^/docs/hotchocolate/(v12|v13)/schema/directives/?$ /docs/hotchocolate/$1/defining-a-schema/directives permanent; + + # schema/enum-type -> defining-a-schema/enums + rewrite ^/docs/hotchocolate/(v12|v13)/schema/enum-type/?$ /docs/hotchocolate/$1/defining-a-schema/enums permanent; + + # schema/input-object-type -> defining-a-schema/input-object-types + rewrite ^/docs/hotchocolate/(v12|v13)/schema/input-object-type/?$ /docs/hotchocolate/$1/defining-a-schema/input-object-types permanent; + + # schema/interface-type -> defining-a-schema/interfaces + rewrite ^/docs/hotchocolate/(v12|v13)/schema/interface-type/?$ /docs/hotchocolate/$1/defining-a-schema/interfaces permanent; + + # schema/object-type -> defining-a-schema/object-types + rewrite ^/docs/hotchocolate/(v12|v13)/schema/object-type/?$ /docs/hotchocolate/$1/defining-a-schema/object-types permanent; + + # schema/relay -> defining-a-schema/relay + rewrite ^/docs/hotchocolate/(v12|v13)/schema/relay/?$ /docs/hotchocolate/$1/defining-a-schema/relay permanent; + + # schema/resolvers -> fetching-data/resolvers + rewrite ^/docs/hotchocolate/(v12|v13)/schema/resolvers/?$ /docs/hotchocolate/$1/fetching-data/resolvers permanent; + + # schema/union-type -> defining-a-schema/unions + rewrite ^/docs/hotchocolate/(v12|v13)/schema/union-type/?$ /docs/hotchocolate/$1/defining-a-schema/unions permanent; + + # data-fetching -> fetching-data/dataloader + rewrite ^/docs/hotchocolate/(v12|v13)/data-fetching/?$ /docs/hotchocolate/$1/fetching-data/dataloader permanent; + + # data-fetching/pagination -> fetching-data/pagination + rewrite ^/docs/hotchocolate/(v12|v13)/data-fetching/pagination/?$ /docs/hotchocolate/$1/fetching-data/pagination permanent; + + # data-fetching/filters -> fetching-data/filtering + rewrite ^/docs/hotchocolate/(v12|v13)/data-fetching/filters/?$ /docs/hotchocolate/$1/fetching-data/filtering permanent; + + # execution-engine -> performance/persisted-queries + rewrite ^/docs/hotchocolate/(v12|v13)/execution-engine/?$ /docs/hotchocolate/$1/performance/persisted-queries permanent; + + # execution-engine/apollo-tracing -> server/instrumentation#apollo-tracing + rewrite ^/docs/hotchocolate/(v12|v13)/execution-engine/apollo-tracing/?$ /docs/hotchocolate/$1/server/instrumentation#apollo-tracing permanent; + + # execution-engine/custom-context-data -> execution-engine + rewrite ^/docs/hotchocolate/(v12|v13)/execution-engine/custom-context-data/?$ /docs/hotchocolate/$1/execution-engine permanent; + + # execution-engine/instrumentation -> server/instrumentation + rewrite ^/docs/hotchocolate/(v12|v13)/execution-engine/instrumentation/?$ /docs/hotchocolate/$1/server/instrumentation permanent; + + # execution-engine/persisted-queries -> performance/persisted-queries + rewrite ^/docs/hotchocolate/(v12|v13)/execution-engine/persisted-queries/?$ /docs/hotchocolate/$1/performance/persisted-queries permanent; + + # execution-engine/subscriptions -> defining-a-schema/subscriptions + rewrite ^/docs/hotchocolate/(v12|v13)/execution-engine/subscriptions/?$ /docs/hotchocolate/$1/defining-a-schema/subscriptions permanent; + + # execution-engine/type-conversion -> defining-a-schema/scalars#custom-converters + rewrite ^/docs/hotchocolate/(v12|v13)/execution-engine/type-conversion/?$ /docs/hotchocolate/$1/defining-a-schema/scalars#custom-converters permanent; + + # security/security -> security + rewrite ^/docs/hotchocolate/(v12|v13)/security/security/?$ /docs/hotchocolate/$1/security permanent; + + # stitching -> distributed-schema + rewrite ^/docs/hotchocolate/(v12|v13)/stitching/?$ /docs/hotchocolate/$1/distributed-schema permanent; + + # tutorials -> integrations/entity-framework + rewrite ^/docs/hotchocolate/(v12|v13)/tutorials/?$ /docs/hotchocolate/$1/integrations/entity-framework permanent; + } + + location /img/projects { + # green donut + rewrite ^/img/projects/greendonut-banner.svg$ /resources/greendonut-banner.svg permanent; + rewrite ^/img/projects/greendonut-signet.svg$ /resources/greendonut-signet.svg permanent; + + # hot chocolate + rewrite ^/img/projects/hotchocolate-banner.svg$ /resources/hotchocolate-banner.svg permanent; + rewrite ^/img/projects/hotchocolate-signet.svg$ /resources/hotchocolate-signet.svg permanent; + + # react rasta + rewrite ^/img/projects/react-rsata-banner.svg$ /resources/react-rsata-banner.svg permanent; + rewrite ^/img/projects/react-rsata-signet.svg$ /resources/react-rsata-signet.svg permanent; + + # strawberry shake + rewrite ^/img/projects/strawberryshake-banner.svg$ /resources/strawberryshake-banner.svg permanent; + rewrite ^/img/projects/strawberryshake-signet.svg$ /resources/strawberryshake-signet.svg permanent; } } diff --git a/website/gatsby-node.js b/website/gatsby-node.js index 87b30233843..7d22f3f761d 100644 --- a/website/gatsby-node.js +++ b/website/gatsby-node.js @@ -4,7 +4,7 @@ const git = require("simple-git/promise"); /** @type import('gatsby').GatsbyNode["createPages"] */ exports.createPages = async ({ actions, graphql, reporter }) => { - const { createPage, createRedirect } = actions; + const { createPage } = actions; const result = await graphql(` { @@ -59,135 +59,6 @@ exports.createPages = async ({ actions, graphql, reporter }) => { const products = result.data.productsConfig.products; createDocPages(createPage, result.data.docs, products); - - // Docs - createPermanentRedirectWithAndWithoutEndSlash( - "/docs", - "/docs/hotchocolate", - createRedirect - ); - - const hotchocolate = products.find((p) => p.path === "hotchocolate"); - - if (hotchocolate) { - createHotChocolateRedirects(hotchocolate, createRedirect); - } - - // Hot Chocolate - createPermanentRedirectWithAndWithoutEndSlash( - "/docs/hotchocolate/get-started", - "/docs/hotchocolate/get-started-with-graphql-in-net-core", - createRedirect - ); - createPermanentRedirectWithAndWithoutEndSlash( - "/docs/hotchocolate/v12/get-started", - "/docs/hotchocolate/v12/get-started-with-graphql-in-net-core", - createRedirect - ); - createPermanentRedirectWithAndWithoutEndSlash( - "/docs/hotchocolate/v13/get-started", - "/docs/hotchocolate/v13/get-started-with-graphql-in-net-core", - createRedirect - ); - - // Marshmallow Pie - createPermanentRedirectWithAndWithoutEndSlash( - "/docs/marshmallowpie", - "/docs/hotchocolate", - createRedirect - ); - - // Blog - createPermanentRedirectWithAndWithoutEndSlash( - "/blog/2019/03/18/entity-framework", - "/blog/2020/03/18/entity-framework", - createRedirect - ); - - // Banana Cake Pop - createPermanentRedirectWithAndWithoutEndSlash( - "/banana-cake-pop", - "/products/bananacakepop", - createRedirect - ); - - // Products - createPermanentRedirectWithAndWithoutEndSlash( - "/products", - "/", - createRedirect - ); - - // Company - createPermanentRedirectWithAndWithoutEndSlash( - "/company", - "/", - createRedirect - ); - - // Services - createPermanentRedirectWithAndWithoutEndSlash( - "/services", - "/services/support", - createRedirect - ); - - // Support - createPermanentRedirectWithAndWithoutEndSlash( - "/support", - "/services/support", - createRedirect - ); - - // Images - createRedirect({ - fromPath: "/img/projects/greendonut-banner.svg", - toPath: "/resources/greendonut-banner.svg", - redirectInBrowser: true, - isPermanent: true, - }); - createRedirect({ - fromPath: "/img/projects/greendonut-signet.png", - toPath: "/resources/greendonut-signet.png", - redirectInBrowser: true, - isPermanent: true, - }); - createRedirect({ - fromPath: "/img/projects/hotchocolate-banner.svg", - toPath: "/resources/hotchocolate-banner.svg", - redirectInBrowser: true, - isPermanent: true, - }); - createRedirect({ - fromPath: "/img/projects/hotchocolate-signet.png", - toPath: "/resources/hotchocolate-signet.png", - redirectInBrowser: true, - isPermanent: true, - }); - createRedirect({ - fromPath: "/img/projects/react-rasta-banner.svg", - toPath: "/resources/react-rasta-banner.svg", - redirectInBrowser: true, - isPermanent: true, - }); - createRedirect({ - fromPath: "/img/projects/react-rasta-signet.png", - toPath: "/resources/react-rasta-signet.png", - redirectInBrowser: true, - isPermanent: true, - }); - createRedirect({ - fromPath: "/img/projects/strawberryshake-banner.svg", - toPath: "/resources/strawberryshake-banner.svg", - redirectInBrowser: true, - isPermanent: true, - }); - createRedirect({ - fromPath: "/img/projects/strawberryshake-signet.png", - toPath: "/resources/strawberryshake-signet.png", - redirectInBrowser: true, - isPermanent: true, - }); }; exports.onCreateNode = async ({ node, actions, getNode, reporter }) => { @@ -348,164 +219,6 @@ function createDocPages(createPage, data, products) { }); } -function createHotChocolateRedirects(product, createRedirect) { - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/code-first`, - toPath: "/docs/hotchocolate/defining-a-schema", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/schema-first`, - toPath: "/docs/hotchocolate/defining-a-schema", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/schema`, - toPath: "/docs/hotchocolate/defining-a-schema", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/schema/object-type`, - toPath: "/docs/hotchocolate/defining-a-schema/object-types", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/schema/interface-type`, - toPath: "/docs/hotchocolate/defining-a-schema/interfaces", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/schema/union-type`, - toPath: "/docs/hotchocolate/defining-a-schema/unions", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/schema/input-object-type`, - toPath: "/docs/hotchocolate/defining-a-schema/input-object-types", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/schema/enum-type`, - toPath: "/docs/hotchocolate/defining-a-schema/enums", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/schema/descriptions`, - toPath: "/docs/hotchocolate/defining-a-schema/documentation", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/schema/custom-scalar-types`, - toPath: "/docs/hotchocolate/defining-a-schema/scalars", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/schema/directives`, - toPath: "/docs/hotchocolate/defining-a-schema/directives", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/schema/relay`, - toPath: "/docs/hotchocolate/defining-a-schema/relay", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/schema/resolvers`, - toPath: "/docs/hotchocolate/fetching-data/resolvers", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/data-fetching`, - toPath: "/docs/hotchocolate/fetching-data/dataloader", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/data-fetching/pagination`, - toPath: "/docs/hotchocolate/fetching-data/pagination", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/data-fetching/filters`, - toPath: "/docs/hotchocolate/fetching-data/filtering", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/execution-engine/instrumentation`, - toPath: "/docs/hotchocolate/server/instrumentation", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/execution-engine/apollo-tracing`, - toPath: "/docs/hotchocolate/server/instrumentation#apollo-tracing", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/execution-engine/persisted-queries`, - toPath: "/docs/hotchocolate/performance/persisted-queries", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/execution-engine/custom-context-data`, - toPath: "/docs/hotchocolate/execution-engine", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/execution-engine/subscriptions`, - toPath: "/docs/hotchocolate/defining-a-schema/subscriptions", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/execution-engine/type-conversion`, - toPath: "/docs/hotchocolate/defining-a-schema/scalars#custom-converters", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/execution-engine/type-conversion`, - toPath: "/docs/hotchocolate/defining-a-schema/scalars#custom-converters", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/security/security`, - toPath: "/docs/hotchocolate/security", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/stitching`, - toPath: "/docs/hotchocolate/distributed-schema", - redirectInBrowser: true, - }); - - createRedirect({ - fromPath: `/docs/hotchocolate/${product.latestStableVersion}/tutorials`, - toPath: "/docs/hotchocolate/integrations/entity-framework", - redirectInBrowser: true, - }); -} - const productAndVersionPattern = /^\/docs\/([\w-]+)(?:\/(v\d+))?/; function getProductFromSlug(slug, products) { @@ -539,38 +252,3 @@ function getGitLog(filepath) { return git().log(logOptions); } - -function createPermanentRedirectWithAndWithoutEndSlash( - fromPath, - toPath, - createRedirect -) { - createRedirect({ - fromPath: ensurePathEndsWithoutSlash(fromPath), - toPath: ensurePathEndsWithoutSlash(toPath), - redirectInBrowser: true, - isPermanent: true, - }); - createRedirect({ - fromPath: ensurePathEndsWithSlash(fromPath), - toPath: ensurePathEndsWithoutSlash(toPath), - redirectInBrowser: true, - isPermanent: true, - }); -} - -function ensurePathEndsWithSlash(path) { - if (path.length > 1 && path[path.length - 1] === "/") { - return path; - } - - return path + "/"; -} - -function ensurePathEndsWithoutSlash(path) { - if (path.length > 1 && path[path.length - 1] === "/") { - return path.substring(0, path.length - 1); - } - - return path; -}