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(core): fix page redirects comparison #1563

Merged
merged 1 commit into from
May 21, 2024
Merged
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
19 changes: 7 additions & 12 deletions packages/core/src/app/prepare/prepareRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,15 @@ const resolvePageRedirects = ({ path, pathInferred }: Page): string[] => {
// paths that should redirect to this page, use set to dedupe
const redirectsSet = new Set<string>()

// add redirect to the set when the redirect could not be normalized & encoded to the page path
const addRedirect = (redirect: string): void => {
const normalizedPath = normalizeRoutePath(redirect)
if (normalizedPath === path) return

const encodedPath = encodeURI(normalizedPath)
if (encodedPath === path) return

redirectsSet.add(redirect)
}

// redirect from inferred path, notice that the inferred path is not uri-encoded
if (pathInferred !== null) {
addRedirect(encodeURI(pathInferred))
const normalizedPathInferred = normalizeRoutePath(pathInferred)
const encodedPathInferred = encodeURI(normalizedPathInferred)

// add redirect to the set when the redirect could not be normalized & encoded to the page path
if (normalizedPathInferred !== path && encodedPathInferred !== path) {
redirectsSet.add(encodedPathInferred)
Copy link
Member

@meteorlxy meteorlxy May 20, 2024

Choose a reason for hiding this comment

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

Maybe we don't need the set anymore? After several iterations, there's only one possible redirect here?

Copy link
Member Author

@Mister-Hope Mister-Hope May 21, 2024

Choose a reason for hiding this comment

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

I think we should still compare the both because users might set a /中文.html manually. And this extra compare would not take much time.

Copy link
Member

Choose a reason for hiding this comment

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

我是说,是不是不需要这个 set 了

}
}

return Array.from(redirectsSet)
Expand Down
Loading