-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Dynamically append path alias (aaa/bbb.html = aaa/bbb = aaa/bbb/) int… #783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically append path alias (aaa/bbb.html = aaa/bbb = aaa/bbb/) int… #783
Conversation
…o redirects during gatsby onCreateNode callback API to avoid 404
Deploy preview for reactjs ready! Built with commit eed1eaa |
(1) markdown without redirects (2) duplicated permalink for /docs/pure-render-mixin.html, rename the unused one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, can you make a couple updates please?
gatsby/onCreateNode.js
Outdated
@@ -9,6 +9,22 @@ | |||
// Parse date information out of blog post filename. | |||
const BLOG_POST_FILENAME_REGEX = /([0-9]+)\-([0-9]+)\-([0-9]+)\-(.+)\.md$/; | |||
|
|||
function buildRedirectString(permalink, redirect_from) { | |||
if (!permalink || permalink.indexOf('.html') === -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of indexOf, can we do !permalink.endsWith('.html')
so it won't catch if there is .html elsewhere in the name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: endsWith()
isn't supported by IE unless we polyfill it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sorta assumed this runs at build time. If not, !/\.html$/.test(permalink)
would work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. I think you're right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will do that!
gatsby/onCreateNode.js
Outdated
return ''; | ||
} | ||
|
||
let basePath = permalink.slice(0, permalink.indexOf('.html')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.slice(0, -'.html'.length)
gatsby/onCreateNode.js
Outdated
@@ -9,6 +9,22 @@ | |||
// Parse date information out of blog post filename. | |||
const BLOG_POST_FILENAME_REGEX = /([0-9]+)\-([0-9]+)\-([0-9]+)\-(.+)\.md$/; | |||
|
|||
function buildRedirectString(permalink, redirect_from) { | |||
if (!permalink || permalink.indexOf('.html') === -1) { | |||
return ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should return redirect_from.
gatsby/onCreateNode.js
Outdated
let redirects = [basePath, basePath + '/']; | ||
if (Array.isArray(redirect_from)) { | ||
redirects = redirects.concat(redirect_from); | ||
//} else if (redirect_from) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove these commented lines
@@ -3,7 +3,7 @@ id: pure-render-mixin | |||
title: PureRenderMixin | |||
layout: docs | |||
category: Reference | |||
permalink: docs/pure-render-mixin.html | |||
permalink: docs/pure-render-mixin-old.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file ever accessible? If not let's just delete it.
@sophiebits Thanks for the solid review! I have learned something from them. I follow most of your suggestions, with some minor differences listed below:
Thanks! |
Hi, @sophiebits just want to know if I should further update this PR? Looks like this issue is still there. (sorry for poking, I know you guys are definitely busy) Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good, sorry for the delay!
This PR tries to fix #605
The issue is following 404 pages, such as:
https://reactjs.org/docs/hello-world
https://reactjs.org/docs/hello-world/
As we can see, only https://reactjs.org/docs/hello-world.html can work correctly. The common alias we consider the same as it won't work.
The brute force approach for this issue might be simply modifying all *.md files for the
redirect_from
to include the alias paths. However, I think a better approach will be to append those alias path dynamically during gatsby'sonCreateNode
API.