Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions src/plugins/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,37 @@ export async function init(config, vm) {
return count++;
}

const saveIfCompleted = () => {
if (len === ++count) {
saveData(config.maxAge, expireKey).catch(err => {
// eslint-disable-next-line no-console
console.warn('Search plugin: failed to save index data', err);
});
}
};

Docsify.get(vm.router.getFile(path), false, vm.config.requestHeaders).then(
async result => {
INDEXES[path] = genIndex(
result => {
try {
INDEXES[path] = genIndex(
path,
result,
vm.router,
config.depth,
indexKey,
);
} finally {
saveIfCompleted();
}
},
err => {
// eslint-disable-next-line no-console
console.warn(
'Search plugin: failed to load a file for indexing',
path,
result,
vm.router,
config.depth,
indexKey,
err,
);
if (len === ++count) {
await saveData(config.maxAge, expireKey);
}
saveIfCompleted();
},
);
});
Expand Down
32 changes: 32 additions & 0 deletions test/e2e/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,36 @@ console.log('Hello World');
'...SearchHere to check it!...',
);
});

test('search should work if some page failed to load', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# Hello World

This is the homepage.
`,
sidebar: `
- [Test Page](test)
- [Broken Page](broken)
`,
},
routes: {
'/test.md': `
# Test Page

This is a custom route.
`,
},
scriptURLs: ['/dist/plugins/search.js'],
};

const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel .title');

await docsifyInit(docsifyInitConfig);

await searchFieldElm.fill('hello');
await expect(resultsHeadingElm).toHaveText('Hello World');
});
});