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

search result should not contain locale in the url #503

Open
huozhi opened this issue May 25, 2023 · 1 comment
Open

search result should not contain locale in the url #503

huozhi opened this issue May 25, 2023 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@huozhi
Copy link
Member

huozhi commented May 25, 2023

When you search in swr-site docs, the url contain .<locale>, which is not expected, the url should only contain the url without .<locale>

Current unexpected behavior

image
@huozhi huozhi added bug Something isn't working help wanted Extra attention is needed labels May 25, 2023
@guilherssousa
Copy link
Contributor

guilherssousa commented Jul 13, 2023

I initially suppose this is a nextra problem, since we don't have bunch of options to tweak flexsearch, so here are the things I gathered, after some testing, I found something interesting:

On nextra/loader tests, it may suggest this is default behaviour: https://github.com/shuding/nextra/blob/fb1f96ed87e1dd492313238cb3439bbfdea890a9/packages/nextra/__test__/locale.test.ts

On nextra/loader#134:142 there's a pageNextRoute that is passed to nextraSearch, which is later used on nextra search plugin to map contents into static chunks on .next folder.

const pageNextRoute =
    '/' +
    slash(path.relative(PAGES_DIR, mdxPath))
      // Remove the `mdx?` extension
      .replace(MARKDOWN_EXTENSION_REGEX, '')
      // Remove the `*/index` suffix
      .replace(/\/index$/, '')
      // Remove the only `index` route
      .replace(/^index$/, '')

Thanks to this, https://swr.vercel.app/ru/docs/prefetching.ru for example is a valid link, and all links with locale after domain name and at the end will work. If you change one of them, the link goes 404.
Since the link is just a interpolation of contents, would it make sense to just a new replace on the pageNextRoute chain to remove the locale?

This would require a PR on Nextra's repository but I got interested on trying out, so if there's space to me to do it, i would like to try @shuding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants