Skip to content

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

Merged
merged 3 commits into from
Jul 13, 2018

Conversation

whitedogg13
Copy link
Contributor

@whitedogg13 whitedogg13 commented Apr 9, 2018

This PR tries to fix #605

The issue is following 404 pages, such as:

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's onCreateNode API.

…o redirects during gatsby onCreateNode callback API to avoid 404
@reactjs-bot
Copy link

reactjs-bot commented Apr 9, 2018

Deploy preview for reactjs ready!

Built with commit eed1eaa

https://deploy-preview-783--reactjs.netlify.com

(1) markdown without redirects
(2) duplicated permalink for /docs/pure-render-mixin.html, rename the unused one
Copy link
Member

@sophiebits sophiebits left a 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?

@@ -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) {
Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will do that!

return '';
}

let basePath = permalink.slice(0, permalink.indexOf('.html'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.slice(0, -'.html'.length)

@@ -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 '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should return redirect_from.

let redirects = [basePath, basePath + '/'];
if (Array.isArray(redirect_from)) {
redirects = redirects.concat(redirect_from);
//} else if (redirect_from) {
Copy link
Member

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
Copy link
Member

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.

@whitedogg13
Copy link
Contributor Author

whitedogg13 commented Apr 13, 2018

@sophiebits Thanks for the solid review! I have learned something from them.

I follow most of your suggestions, with some minor differences listed below:

  • I'm not sure if the old content/docs/reference-pure-render-mixin.md is indeed not used at all (since the permalink is duplicated, it's hard to grep), so I think it's safer to just rename it and keep it that way.
  • for the case (!permalink || !permalink.endsWith('.html')), directly return redirect_from might cause error since the redirect_from might be an array, but caller expects this function to return a string (so this function is named buildRedirectString, as a hint). I also consider the case against stringifying undefined or null in the latest mod.

Thanks!

@whitedogg13
Copy link
Contributor Author

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!

Copy link
Member

@sophiebits sophiebits left a 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!

@sophiebits sophiebits merged commit e52e6c6 into reactjs:master Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test Utils page is available in Google search results, but the front-end redirects the visitor
5 participants