fix(build): uniform handling of windows slash in localSearchPlugin (#2358)

pull/2359/head
烽宁 2 years ago committed by GitHub
parent 2f482afaab
commit b31933fbdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,7 +29,6 @@ import {
import type { ModalTranslations } from '../../../../types/local-search'
import { dataSymbol } from '../../app/data'
import { pathToFile } from '../../app/utils'
import { slash } from '../../shared'
import { useData } from '../composables/data'
import { createTranslate } from '../support/translation'
@ -218,7 +217,7 @@ debouncedWatch(
)
async function fetchExcerpt(id: string) {
const file = pathToFile(slash(id.slice(0, id.indexOf('#'))))
const file = pathToFile(id.slice(0, id.indexOf('#')))
try {
return { id, mod: await import(/*@vite-ignore*/ file) }
} catch (e) {

@ -60,7 +60,7 @@ export async function localSearchPlugin(
}
function getLocaleForPath(file: string) {
const relativePath = path.relative(siteConfig.srcDir, file)
const relativePath = slash(path.relative(siteConfig.srcDir, file))
const siteData = resolveSiteDataByRoute(siteConfig.site, relativePath)
return siteData?.localeIndex ?? 'root'
}
@ -97,7 +97,7 @@ export async function localSearchPlugin(
function getDocId(file: string) {
let relFile = slash(path.relative(siteConfig.srcDir, file))
relFile = siteConfig.rewrites.map[relFile] || relFile
let id = path.join(siteConfig.site.base, relFile)
let id = slash(path.join(siteConfig.site.base, relFile))
id = id.replace(/\/index\.md$/, '/')
id = id.replace(/\.md$/, siteConfig.cleanUrls ? '' : '.html')
return id

Loading…
Cancel
Save