@@ -25,13 +25,16 @@ const lunr = require("../lunr.js") as (
25
25
const readFileAsync = util . promisify ( fs . readFile ) ;
26
26
const writeFileAsync = util . promisify ( fs . writeFile ) ;
27
27
28
- // FIXME: Duplicated in src/theme/SearchBar/util.js
29
28
function urlMatchesPrefix ( url : string , prefix : string ) {
30
29
if ( prefix . startsWith ( "/" ) ) {
31
- throw new Error ( `prefix must not start with a /. This is a bug.` ) ;
30
+ throw new Error (
31
+ `prefix must not start with a /. This is a bug (url: "${ url } ", prefix: ${ prefix } ).`
32
+ ) ;
32
33
}
33
34
if ( prefix . endsWith ( "/" ) ) {
34
- throw new Error ( `prefix must not end with a /. This is a bug.` ) ;
35
+ throw new Error (
36
+ `prefix must not end with a /. This is a bug (url: "${ url } ", prefix: ${ prefix } ).`
37
+ ) ;
35
38
}
36
39
return prefix === "" || url === prefix || url . startsWith ( `${ prefix } /` ) ;
37
40
}
@@ -356,10 +359,12 @@ export const tokenize = (input) => lunr.tokenizer(input)
356
359
}
357
360
if ( indexDocs ) {
358
361
for ( const docsPlugin of docsPlugins . values ( ) ) {
359
- const docsBasePath = trimTrailingSlash (
360
- docsPlugin . options . routeBasePath
362
+ const docsBasePath = trimLeadingSlash (
363
+ trimTrailingSlash ( docsPlugin . options . routeBasePath )
364
+ ) ;
365
+ const docsTagsPath = trimLeadingSlash (
366
+ trimTrailingSlash ( docsPlugin . options . tagsBasePath )
361
367
) ;
362
- const docsTagsPath = docsPlugin . options . tagsBasePath ;
363
368
364
369
if ( urlMatchesPrefix ( route , docsBasePath ) ) {
365
370
if (
@@ -385,10 +390,12 @@ export const tokenize = (input) => lunr.tokenizer(input)
385
390
}
386
391
if ( indexBlog ) {
387
392
for ( const blogPlugin of blogPlugins . values ( ) ) {
388
- const blogBasePath = trimTrailingSlash (
389
- blogPlugin . options . routeBasePath
393
+ const blogBasePath = trimLeadingSlash (
394
+ trimTrailingSlash ( blogPlugin . options . routeBasePath )
395
+ ) ;
396
+ const blogTagsPath = trimLeadingSlash (
397
+ trimTrailingSlash ( blogPlugin . options . tagsBasePath )
390
398
) ;
391
- const blogTagsPath = blogPlugin . options . tagsBasePath ;
392
399
393
400
if ( urlMatchesPrefix ( route , blogBasePath ) ) {
394
401
if (
@@ -415,8 +422,8 @@ export const tokenize = (input) => lunr.tokenizer(input)
415
422
}
416
423
if ( indexPages ) {
417
424
for ( const pagesPlugin of pagesPlugins . values ( ) ) {
418
- const pagesBasePath = trimTrailingSlash (
419
- pagesPlugin . options . routeBasePath
425
+ const pagesBasePath = trimLeadingSlash (
426
+ trimTrailingSlash ( pagesPlugin . options . routeBasePath )
420
427
) ;
421
428
422
429
if ( urlMatchesPrefix ( route , pagesBasePath ) ) {
0 commit comments