mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-12-03 12:39:41 +08:00
fix: fix search with no content. (#1878)
This commit is contained in:
parent
9832805681
commit
9b74744299
@ -211,14 +211,15 @@ export function search(query) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const matchContent =
|
const matchContent =
|
||||||
|
handlePostContent &&
|
||||||
'...' +
|
'...' +
|
||||||
handlePostContent
|
handlePostContent
|
||||||
.substring(start, end)
|
.substring(start, end)
|
||||||
.replace(
|
.replace(
|
||||||
regEx,
|
regEx,
|
||||||
word => `<em class="search-keyword">${word}</em>`
|
word => `<em class="search-keyword">${word}</em>`
|
||||||
) +
|
) +
|
||||||
'...';
|
'...';
|
||||||
|
|
||||||
resultStr += matchContent;
|
resultStr += matchContent;
|
||||||
}
|
}
|
||||||
|
@ -176,4 +176,24 @@ test.describe('Search Plugin Tests', () => {
|
|||||||
await searchFieldElm.fill('hello');
|
await searchFieldElm.fill('hello');
|
||||||
await expect(resultsHeadingElm).toHaveText('Changelog Title');
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user