fix: fix search with no content. (#1878)

This commit is contained in:
Koy Zhuang 2022-09-17 19:01:35 +08:00 committed by GitHub
parent 9832805681
commit 9b74744299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 7 deletions

View File

@ -211,14 +211,15 @@ export function search(query) {
}
const matchContent =
handlePostContent &&
'...' +
handlePostContent
.substring(start, end)
.replace(
regEx,
word => `<em class="search-keyword">${word}</em>`
) +
'...';
handlePostContent
.substring(start, end)
.replace(
regEx,
word => `<em class="search-keyword">${word}</em>`
) +
'...';
resultStr += matchContent;
}

View File

@ -176,4 +176,24 @@ test.describe('Search Plugin Tests', () => {
await searchFieldElm.fill('hello');
await expect(resultsHeadingElm).toHaveText('Changelog Title');
});
test('search when there is no body', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# EmptyContent
---
---
`,
},
scriptURLs: ['/lib/plugins/search.min.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel h2');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('empty');
await expect(resultsHeadingElm).toHaveText('EmptyContent');
});
});