diff --git a/src/plugins/search/search.js b/src/plugins/search/search.js index 91a2109..3266b7b 100644 --- a/src/plugins/search/search.js +++ b/src/plugins/search/search.js @@ -211,14 +211,15 @@ export function search(query) { } const matchContent = + handlePostContent && '...' + - handlePostContent - .substring(start, end) - .replace( - regEx, - word => `${word}` - ) + - '...'; + handlePostContent + .substring(start, end) + .replace( + regEx, + word => `${word}` + ) + + '...'; resultStr += matchContent; } diff --git a/test/e2e/search.test.js b/test/e2e/search.test.js index cab6451..ed79f05 100644 --- a/test/e2e/search.test.js +++ b/test/e2e/search.test.js @@ -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'); + }); });