From 5f21aef23c355820f248ffc74fc1fa7d2e8afef6 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Mon, 5 Feb 2024 21:19:53 +0530 Subject: [PATCH] update regexes --- src/shared/shared.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/shared/shared.ts b/src/shared/shared.ts index e470825e..7964f0af 100644 --- a/src/shared/shared.ts +++ b/src/shared/shared.ts @@ -16,9 +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 = /\.(md|html)$/ -export const INDEX_RE = /\/index$/ + +const HASH_RE = /#.*$/ +const HASH_OR_QUERY_RE = /[?#].*$/ +const INDEX_OR_EXT_RE = /(?:(^|\/)index)?\.(?:md|html)$/ export const inBrowser = typeof document !== 'undefined' @@ -61,8 +62,10 @@ export function isActive( return true } -export function normalize(path: string): string { - return decodeURI(path).replace(HASH_RE, '').replace(EXT_RE, '').replace(INDEX_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 {