Skip to content

Commit

Permalink
Refactor of search plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pbochynski committed Sep 27, 2024
1 parent 5fd5a7f commit 6b81205
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
search: {
maxAge: 3600000, // Expiration time - 1 hour
paths: 'auto',
pathsWithSidebars: [
sidebars: [
'/',
'/istio/user/',
'/btp-manager/user/',
Expand Down
2 changes: 1 addition & 1 deletion docs/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const install = function (hook, vm) {
opts.hideOtherSidebarContent || CONFIG.hideOtherSidebarContent;
CONFIG.namespace = opts.namespace || CONFIG.namespace;
CONFIG.pathNamespaces = opts.pathNamespaces || CONFIG.pathNamespaces;
CONFIG.pathsWithSidebars = opts.pathsWithSidebars
CONFIG.sidebars = opts.sidebars
}

const isAuto = CONFIG.paths === 'auto';
Expand Down
10 changes: 5 additions & 5 deletions docs/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ function extractLinksFromMarkdown(markdownText) {
return links;
}

async function pathsFromSidebars(sidebarsPaths,paths, router) {
async function pathsFromSidebars(sidebarsPaths, router) {
const paths = []
const tasks = []
for (const path of sidebarsPaths) {
tasks.push(
Expand All @@ -255,8 +256,7 @@ async function pathsFromSidebars(sidebarsPaths,paths, router) {
l.url = l.url.startsWith('/') ? l.url : path + l.url
//trim the '.md' extension
l.url = l.url.replace(/\.md$/, '')

if (!paths.some(p => p === l.url)) {
if (paths.indexOf(l.url) === -1) {
paths.push(l.url)
}
}
Expand All @@ -269,8 +269,8 @@ async function pathsFromSidebars(sidebarsPaths,paths, router) {
export async function init(config, vm) {
const isAuto = config.paths === 'auto';
let paths = []
if (config.pathsWithSidebars) {
await pathsFromSidebars(config.pathsWithSidebars,paths,vm.router)
if (config.sidebars) {
paths = await pathsFromSidebars(config.sidebars, vm.router)
} else {
paths = isAuto ? getAllPaths(vm.router) : config.paths;
}
Expand Down

0 comments on commit 6b81205

Please sign in to comment.