Skip to content

Commit

Permalink
fix(theme): correctly normalize paths ending with "index" (#3544)
Browse files Browse the repository at this point in the history
Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
  • Loading branch information
yhzx233 and brc-dd authored Feb 5, 2024
1 parent 67a9964 commit c582a8d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/shared/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export type {

export const EXTERNAL_URL_RE = /^(?:[a-z]+:|\/\/)/i
export const APPEARANCE_KEY = 'vitepress-theme-appearance'
export const HASH_RE = /#.*$/
export const EXT_RE = /(index)?\.(md|html)$/

const HASH_RE = /#.*$/
const HASH_OR_QUERY_RE = /[?#].*$/
const INDEX_OR_EXT_RE = /(?:(^|\/)index)?\.(?:md|html)$/

export const inBrowser = typeof document !== 'undefined'

Expand Down Expand Up @@ -60,8 +62,10 @@ export function isActive(
return true
}

export function normalize(path: string): string {
return decodeURI(path).replace(HASH_RE, '').replace(EXT_RE, '')
function normalize(path: string): string {
return decodeURI(path)
.replace(HASH_OR_QUERY_RE, '')
.replace(INDEX_OR_EXT_RE, '$1')
}

export function isExternal(path: string): boolean {
Expand Down

0 comments on commit c582a8d

Please sign in to comment.