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: langRoutePrefix should end with slash #1539

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

JounQin
Copy link
Contributor

@JounQin JounQin commented Oct 30, 2024

Summary

langRoutePrefix is used at

href={localeData.langRoutePrefix}

Without the trailing slash, for located pages, it renders /zh for example, which means /zh.html but it should be /zh/index.html actually. And this change matches the default langRoutePrefix (/).

Related Issue

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copy link

netlify bot commented Oct 30, 2024

Deploy Preview for aquamarine-blini-95325f ready!

Name Link
🔨 Latest commit 5f94ea0
🔍 Latest deploy log https://app.netlify.com/sites/aquamarine-blini-95325f/deploys/6721d7ef1e6110000816cef7
😎 Deploy Preview https://deploy-preview-1539--aquamarine-blini-95325f.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 91 (🟢 up 11 from production)
Accessibility: 97 (no change from production)
Best Practices: 92 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@Timeless0911
Copy link
Contributor

Timeless0911 commented Oct 30, 2024

I think we should only modify code here

href={localeData.langRoutePrefix}

instead of the public hook of useLocaleSiteData which may brings breaking changes.

@JounQin
Copy link
Contributor Author

JounQin commented Oct 30, 2024

@Timeless0911 The default langRoutePrefix is /, so I believe langRoutePrefix should always end with slash?

@Timeless0911
Copy link
Contributor

The default langRoutePrefix is /, so I believe langRoutePrefix should always end with slash?

I cannot confirm whether the modification of this hook will affect the use in other places and other users who import it at runtime. In addition, personally I think langRoutePrefix should be '' and zh, just like what sidebar component do in

const langRoutePrefix = normalizeSlash(localesData.langRoutePrefix || '');

This should be optimized with normalizeHref function together in the future, rspress.dev/index rspress.dev/zh/index is ugly than rspress.dev rspress.dev/zh

export function normalizeHref(url?: string, cleanUrls = false) {
if (!url) {
return '/';
}
if (isExternalUrl(url)) {
return url;
}
// eslint-disable-next-line prefer-const
let { url: cleanUrl, hash } = parseUrl(decodeURIComponent(url));
if (!cleanUrls && !cleanUrl.endsWith('.html')) {
if (cleanUrl.endsWith('/')) {
cleanUrl += 'index.html';
} else {
cleanUrl += '.html';
}
}
if (cleanUrls && cleanUrl.endsWith('/')) {
cleanUrl += 'index';
}
if (cleanUrls && cleanUrl.endsWith('.html')) {
cleanUrl = cleanUrl.replace(/\.html$/, '');
}
return addLeadingSlash(hash ? `${cleanUrl}#${hash}` : cleanUrl);
}

@JounQin
Copy link
Contributor Author

JounQin commented Oct 30, 2024

In addition, personally I think langRoutePrefix should be '' and zh, just like what sidebar component do in

There is a problem that /zh/ (/zh/index.html) and /zh (/zh.html) are totally different.

When toggling language, it goes to /zh/index in https://github.com/web-infra-dev/rspress/blob/main/packages/theme-default/src/components/Nav/NavVersions.tsx.

@Timeless0911
Copy link
Contributor

Timeless0911 commented Oct 30, 2024

This should be an issue related to the href link issue of home page in different languages.

Current

  • navbarTitle zh
    image

  • navbarTitle en
    image

  • translation menu zh
    image

  • translation menu en
    image

Expected

  • rspress.dev in en (default lang)
  • rspress.dev/zh in zh

@Timeless0911
Copy link
Contributor

There is a problem that /zh/ (/zh/index.html) and /zh (/zh.html) are totally different.

Yes, this is a question that needs to be considered. The situation is different when there is an html suffix or not (cleanUrls enabled or not).

@JounQin
Copy link
Contributor Author

JounQin commented Oct 30, 2024

rspress.dev/zh in zh

Is this really expected? As I mentioned, /zh means /zh.html which SSG does not generates at all, rspress.dev/zh/ is fine for /zh/index.html.

@Timeless0911
Copy link
Contributor

Is this really expected? As I mentioned, /zh means /zh.html which SSG does not generates at all, rspress.dev/zh/ is fine for /zh/index.html.

I know what you mean, we should ensure the request is https://rspress.dev/zh/.

@Timeless0911
Copy link
Contributor

Timeless0911 commented Oct 30, 2024

In other words, your changes are no problem for resource requests, but the href display will appear a bit bloated. My goal is to simplify the content after the mouse hovers over it.

image

zh/ or zh with zh/ request is both ok.

@Timeless0911
Copy link
Contributor

I think this PR can be merged for better semantics of link.

@Timeless0911 Timeless0911 enabled auto-merge (squash) October 30, 2024 08:04
@Timeless0911 Timeless0911 merged commit 7b7c965 into web-infra-dev:main Oct 30, 2024
10 checks passed
@JounQin JounQin deleted the fix/langRoutePrefix branch October 30, 2024 08:11
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.

2 participants