vercel / swr-site

The official website for SWR.
https://swr.vercel.app
Apache License 2.0
478 stars 350 forks source link

search result should not contain locale in the url #503

Open huozhi opened 1 year ago

huozhi commented 1 year ago

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
guilherssousa commented 1 year ago

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