Skip to content

Commit 0d2830e

Browse files
authored
feat: extract normalizePath to helper (#671)
1 parent aad5927 commit 0d2830e

8 files changed

Lines changed: 11 additions & 13 deletions

File tree

plugins/tools/plugin-redirect/src/client/composables/setupDevServerRedirect.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { entries, isLinkHttp } from '@vuepress/helper/client'
1+
import { entries, normalizePath, isLinkHttp } from '@vuepress/helper/client'
22
import { usePreferredLanguages, watchImmediate } from '@vueuse/core'
33
import { computed } from 'vue'
44
import {
@@ -11,7 +11,6 @@ import {
1111
import { redirectMap } from '@temp/redirect/map.js'
1212

1313
import type { RedirectBehaviorConfig } from '../../shared/index.js'
14-
import { normalizePath } from '../../shared/index.js'
1514

1615
export const setupDevServerRedirect = ({
1716
autoLocale,

plugins/tools/plugin-redirect/src/node/getRedirectMap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {
44
isArray,
55
isFunction,
66
isPlainObject,
7+
normalizePath,
78
} from '@vuepress/helper'
89
import type { App, Page } from 'vuepress/core'
910

10-
import { normalizePath } from '../shared/normalizePath.js'
1111
import type {
1212
RedirectPluginFrontmatter,
1313
RedirectPluginOptions,

plugins/tools/plugin-redirect/src/node/handleRedirectTo.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { isLinkAbsolute, removeLeadingSlash } from '@vuepress/helper'
1+
import {
2+
isLinkAbsolute,
3+
normalizePath,
4+
removeLeadingSlash,
5+
} from '@vuepress/helper'
26
import type { App, Page } from 'vuepress/core'
37

4-
import { normalizePath } from '../shared/normalizePath.js'
58
import type { RedirectPluginFrontmatter } from './types/index.js'
69

710
export const handleRedirectTo = ({ frontmatter }: Page, app: App): void => {
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export type * from './behavior.js'
22
export type * from './locales.js'
3-
export * from './normalizePath.js'

themes/theme-default/src/client/utils/isActiveSidebarItem.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1+
import { normalizePath } from '@vuepress/helper/client'
12
import type { RouteLocationNormalizedLoaded } from 'vuepress/client'
23

34
import type { SidebarItem } from '../typings.js'
45

5-
const normalizePath = (path: string): string =>
6-
decodeURI(path)
7-
.replace(/#.*$/, '')
8-
.replace(/(index)?\.(md|html)$/, '')
9-
106
const isActiveLink = (
117
link: string,
128
route: RouteLocationNormalizedLoaded,
139
): boolean => {
1410
if (route.hash === link) return true
1511

16-
const currentPath = normalizePath(route.path)
17-
const targetPath = normalizePath(link)
12+
const currentPath = normalizePath(decodeURI(route.path), true)
13+
const targetPath = normalizePath(decodeURI(link), true)
1814
return currentPath === targetPath
1915
}
2016

tools/helper/src/shared/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export type * from './header.js'
44
export * from './helper.js'
55
export * from './link.js'
66
export type * from './locales.js'
7+
export * from './normalizePath.js'
78
export type * from './key.js'
89
export type * from './types.js'
File renamed without changes.

plugins/tools/plugin-redirect/tests/shared/normalizePath.spec.ts renamed to tools/helper/tests/shared/normalizePath.spec.ts

File renamed without changes.

0 commit comments

Comments
 (0)