From 0831134e778660078697cfea54bb9ef17694d8a0 Mon Sep 17 00:00:00 2001 From: i544693 <369491420@qq.com> Date: Mon, 12 Sep 2022 16:21:27 +0800 Subject: [PATCH] fix: fix search with no content. --- src/plugins/search/search.js | 15 ++++++++------- test/e2e/search.test.js | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/plugins/search/search.js b/src/plugins/search/search.js index 91a21094e..3266b7bb4 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 cab645184..ed79f05f9 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'); + }); });