Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: #563 * chore: add changeset
- Loading branch information
Showing
4 changed files
with
35 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'nextra-theme-docs': patch | ||
--- | ||
|
||
fix: query should not affect nav highlight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { describe, it, expect } from 'vitest' | ||
import { getFSRoute } from '../src/utils/get-fs-route' | ||
|
||
describe('getFSRoute', () => { | ||
it('replace locale', () => { | ||
const withLocale = getFSRoute('/getting-started.en-US', 'en-US') | ||
expect(withLocale).toEqual('/getting-started') | ||
}) | ||
it('replace index', () => { | ||
const withIndex = getFSRoute('/getting-started/index') | ||
expect(withIndex).toEqual('/getting-started') | ||
const withIndexAndLocale = getFSRoute('/getting-started/index') | ||
expect(withIndexAndLocale).toEqual('/getting-started') | ||
}) | ||
it('ignore query', () => { | ||
const withQuery = getFSRoute('/getting-started?query=1') | ||
expect(withQuery).toEqual('/getting-started') | ||
|
||
const withQueryLocale = getFSRoute('/getting-started.en-US?query=1', 'en-US') | ||
expect(withQueryLocale).toEqual('/getting-started') | ||
|
||
const withIndexLocaleQuery = getFSRoute('/getting-started/index.en-US?query=1', 'en-US') | ||
expect(withIndexLocaleQuery).toEqual('/getting-started') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
const template = 'https://nextra.vercel.app' | ||
export const getFSRoute = (asPath: string, locale?: string | undefined) => { | ||
const pathname = new URL(asPath, template).pathname | ||
const cleanedPath = locale | ||
? asPath.replace(new RegExp(`\.${locale}(\/|$)`), '$1') | ||
: asPath | ||
|
||
return ( | ||
cleanedPath.replace(new RegExp('/index(/|$)'), '$1').split('#')[0] || '/' | ||
) | ||
? pathname.replace(new RegExp(`\.${locale}(\/|$)`), '$1') | ||
: pathname | ||
return (cleanedPath.replace(new RegExp('/index(/|$)'), '$1').split('#')[0] || '/') | ||
} |