From 1a98da7d98aef075e168baf850fc31bc9cce0df0 Mon Sep 17 00:00:00 2001 From: Emmanuel Fallancy Date: Sun, 22 Oct 2017 23:24:11 +1100 Subject: [PATCH 1/4] Fix the blog slug html creation that leads to improper redirect --- gatsby-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatsby-node.js b/gatsby-node.js index 3abded6b..08bc085b 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -189,7 +189,7 @@ exports.onCreateNode = ({node, boundActionCreators, getNode}) => { const day = match[3]; const filename = match[4]; - slug = `/blog/${year}/${month}/${day}/${filename}.html`; + slug = `blog/${year}/${month}/${day}/${filename}.html`; const date = new Date(year, month - 1, day); From 4f5c11024628f52ead3e4c9cdacddb0b002fbd75 Mon Sep 17 00:00:00 2001 From: Emmanuel Fallancy Date: Mon, 23 Oct 2017 07:40:45 +1100 Subject: [PATCH 2/4] Fix the blog redirect --- gatsby-node.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index 08bc085b..57abadcc 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -124,11 +124,13 @@ exports.createPages = async ({graphql, boundActionCreators}) => { process.exit(1); } + const toPath = slug.startsWith('/') ? slug : `/${slug}` + redirectToSlugMap[fromPath] = slug; createRedirect({ fromPath: `/${fromPath}`, redirectInBrowser: true, - toPath: `/${slug}`, + toPath, }); }); } @@ -189,7 +191,7 @@ exports.onCreateNode = ({node, boundActionCreators, getNode}) => { const day = match[3]; const filename = match[4]; - slug = `blog/${year}/${month}/${day}/${filename}.html`; + slug = `/blog/${year}/${month}/${day}/${filename}.html`; const date = new Date(year, month - 1, day); From e21f2ae94351b4ad3b93005a8ce24e01fa388481 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sun, 22 Oct 2017 13:43:49 -0700 Subject: [PATCH 3/4] Added inline comment. --- gatsby-node.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gatsby-node.js b/gatsby-node.js index 57abadcc..a3eece56 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -124,6 +124,9 @@ exports.createPages = async ({graphql, boundActionCreators}) => { process.exit(1); } + // A leading "/" is required for redirects to work, + // But multiple leading "/" will break redirects. + // For more context see github.com/reactjs/reactjs.org/pull/194 const toPath = slug.startsWith('/') ? slug : `/${slug}` redirectToSlugMap[fromPath] = slug; From 331fd30e59c05fece503922f2f8954ea1686940d Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sun, 22 Oct 2017 13:45:07 -0700 Subject: [PATCH 4/4] Added semicolon to fix Prettier --- gatsby-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatsby-node.js b/gatsby-node.js index a3eece56..89fc1db8 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -127,7 +127,7 @@ exports.createPages = async ({graphql, boundActionCreators}) => { // A leading "/" is required for redirects to work, // But multiple leading "/" will break redirects. // For more context see github.com/reactjs/reactjs.org/pull/194 - const toPath = slug.startsWith('/') ? slug : `/${slug}` + const toPath = slug.startsWith('/') ? slug : `/${slug}`; redirectToSlugMap[fromPath] = slug; createRedirect({