fix search index out of bounds error (#548)

Co-authored-by: spencerwooo <spencer.woo@outlook.com>
This commit is contained in:
浅秋枫影 2022-03-17 12:01:33 +08:00 committed by GitHub
parent 0397fcd52f
commit f7732101e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,13 +27,15 @@ import siteConfig from '../config/site.config'
function mapAbsolutePath(path: string): string {
// path is in the format of '/drive/root:/path/to/file', if baseDirectory is '/' then we split on 'root:',
// otherwise we split on the user defined 'baseDirectory'
const absolutePath = path.split(siteConfig.baseDirectory === '/' ? 'root:' : siteConfig.baseDirectory)[1]
const absolutePath = path.split(siteConfig.baseDirectory === '/' ? 'root:' : siteConfig.baseDirectory)
// path returned by the API may contain #, by doing a decodeURIComponent and then encodeURIComponent we can
// replace URL sensitive characters such as the # with %23
return absolutePath
.split('/')
.map(p => encodeURIComponent(decodeURIComponent(p)))
.join('/')
return absolutePath.length > 1 // solve https://github.com/spencerwooo/onedrive-vercel-index/issues/539
? absolutePath[1]
.split('/')
.map(p => encodeURIComponent(decodeURIComponent(p)))
.join('/')
: ''
}
/**