Skip to content

Instantly share code, notes, and snippets.

@domodomodomo
Created November 2, 2019 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domodomodomo/ac2d4aeb6788579ebd2f2b7f2a7f8e8b to your computer and use it in GitHub Desktop.
Save domodomodomo/ac2d4aeb6788579ebd2f2b7f2a7f8e8b to your computer and use it in GitHub Desktop.
// original
// https://github.com/vuejs/vuepress/blob/ba7f586e2e8173e5e30c345ea6a92ff213925a2e/packages/%40vuepress/theme-default/util/index.js#L188-L215
/**
* @param { Route } route
* @param { Array<string|string[]> | Array<SidebarGroup> | [link: string]: SidebarConfig } config
* @returns { base: string, config: SidebarConfig }
*/
export function resolveMatchingConfig (regularPath, config) {
if (Array.isArray(config)) {
return {
base: '/',
config: config
}
}
for (const base in config) {
// - if (ensureEndingSlash(regularPath).indexOf(encodeURI(base)) === 0) {
// + if (exists(regularPath, config[base])) {
if (exists(regularPath, config[base])) {
return {
base,
config: config[base]
}
}
}
return {}
}
function exists (regularPath, arrayConfig) {
if (arrayConfig === undefined) {
return false
}
for (const item of arrayConfig) {
if (item instanceof Array) {
const path = item[0]
if (ensureEndingSlash(regularPath) === ensureEndingSlash(path)) {
return true
}
} else {
if (exists(regularPath, item.children)) {
return true
}
}
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment