Skip to content
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

Fix page redirect preview #2711

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions readthedocs/templates/projects/project_redirects.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
redirect_target = "/$lang/$version/faq.html";
}
else if (option === "page" ) {
redirect_from = "/$lang/$version/" + field_from_url.val();
redirect_target = "/$lang/$version/" + field_to_url.val();
field_from = field_from_url.val();
field_to = field_to_url.val();
field_from_absolute = (field_from.length > 0) && (field_from[0] === "/");
field_to_absolute = (field_to.length > 0) && (field_to[0] === "/");
Copy link
Contributor

Choose a reason for hiding this comment

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

L27 + L28 are replicating field_to.startsWith() etc

redirect_from = "/$lang/$version" + (field_from_absolute ? "" : "/") + field_from;
redirect_target = "/$lang/$version" + (field_to_absolute ? "" : "/") + field_to;
Copy link
Contributor

Choose a reason for hiding this comment

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

Conditional logic wouldn't be needed here if just using a simple regex to remove leading /. For example:

redirect_from = "/$lang/$version/" + field_from_url.val().replace(/^\/+/, '')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. yes, that's much cleaner, I'll edit the PR accordingly. Thank you for the review.

}
else if (option === "exact" ) {
redirect_from = field_from_url.val();
Expand Down