From 8354f8fb8649d429b2cb525dd6f35127faba7ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=83=BD=E5=AE=81?= Date: Mon, 17 Apr 2023 20:19:40 +0800 Subject: [PATCH] fix(theme): local search showDetailedList not working in windows (#2248) Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> --- src/client/theme-default/components/VPLocalSearchBox.vue | 3 ++- src/node/build/bundle.ts | 3 +-- src/node/build/render.ts | 2 +- src/node/markdownToVue.ts | 8 ++++++-- src/node/plugin.ts | 3 +-- src/node/utils/slash.ts | 3 --- src/shared/shared.ts | 4 ++++ 7 files changed, 15 insertions(+), 11 deletions(-) delete mode 100644 src/node/utils/slash.ts diff --git a/src/client/theme-default/components/VPLocalSearchBox.vue b/src/client/theme-default/components/VPLocalSearchBox.vue index e04d129f..811f8f7b 100644 --- a/src/client/theme-default/components/VPLocalSearchBox.vue +++ b/src/client/theme-default/components/VPLocalSearchBox.vue @@ -26,6 +26,7 @@ import { } from 'vue' import type { ModalTranslations } from '../../../../types/local-search' import { pathToFile } from '../../app/utils' +import { slash } from '../../shared' import { useData } from '../composables/data' import { createTranslate } from '../support/translation' @@ -199,7 +200,7 @@ debouncedWatch( ) async function fetchExcerpt(id: string) { - const file = pathToFile(id.slice(0, id.indexOf('#'))) + const file = slash(pathToFile(id.slice(0, id.indexOf('#')))) try { return { id, mod: await import(/*@vite-ignore*/ file) } } catch (e) { diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index 7a87a501..654f8b8d 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -7,11 +7,10 @@ import { type UserConfig as ViteUserConfig } from 'vite' import type { GetModuleInfo, RollupOutput } from 'rollup' -import { slash } from '../utils/slash' import type { SiteConfig } from '../config' import { APP_PATH } from '../alias' import { createVitePressPlugin } from '../plugin' -import { sanitizeFileName } from '../shared' +import { sanitizeFileName, slash } from '../shared' import { buildMPAClient } from './buildMPAClient' import { fileURLToPath } from 'url' import { normalizePath } from 'vite' diff --git a/src/node/build/render.ts b/src/node/build/render.ts index 4b63535e..b3be8cc9 100644 --- a/src/node/build/render.ts +++ b/src/node/build/render.ts @@ -12,11 +12,11 @@ import { notFoundPageData, resolveSiteDataByRoute, sanitizeFileName, + slash, type HeadConfig, type PageData, type SSGContext } from '../shared' -import { slash } from '../utils/slash' import { deserializeFunctions } from '../utils/fnSerialize' export async function renderPage( diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index 0a67a6c6..056ae1b5 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -11,9 +11,13 @@ import { type MarkdownOptions, type MarkdownRenderer } from './markdown' -import { EXTERNAL_URL_RE, type HeadConfig, type PageData } from './shared' +import { + EXTERNAL_URL_RE, + slash, + type HeadConfig, + type PageData +} from './shared' import { getGitTimestamp } from './utils/getGitTimestamp' -import { slash } from './utils/slash' const debug = _debug('vitepress:md') const cache = new LRUCache({ max: 1024 }) diff --git a/src/node/plugin.ts b/src/node/plugin.ts index 86f95293..c6ab131f 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -1,6 +1,5 @@ import path from 'path' import c from 'picocolors' -import { slash } from './utils/slash' import type { OutputAsset, OutputChunk } from 'rollup' import { mergeConfig, @@ -17,7 +16,7 @@ import { } from './alias' import { resolveUserConfig, resolvePages, type SiteConfig } from './config' import { clearCache, createMarkdownToVueRenderFn } from './markdownToVue' -import type { PageDataPayload } from './shared' +import { slash, type PageDataPayload } from './shared' import { staticDataPlugin } from './plugins/staticDataPlugin' import { webFontsPlugin } from './plugins/webFontsPlugin' import { dynamicRoutesPlugin } from './plugins/dynamicRoutesPlugin' diff --git a/src/node/utils/slash.ts b/src/node/utils/slash.ts deleted file mode 100644 index f06ed939..00000000 --- a/src/node/utils/slash.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function slash(p: string): string { - return p.replace(/\\/g, '/') -} diff --git a/src/shared/shared.ts b/src/shared/shared.ts index f4fc101c..ceab8587 100644 --- a/src/shared/shared.ts +++ b/src/shared/shared.ts @@ -165,3 +165,7 @@ export function sanitizeFileName(name: string): string { .replace(/(^|\/)_+(?=[^/]*$)/, '$1') ) } + +export function slash(p: string): string { + return p.replace(/\\/g, '/') +}