Skip to content

Commit 4e5dae7

Browse files
committed
Squashed commit of the following:
commit a2ebb21 Author: 沈唁 <[email protected]> Date: Sun Nov 8 16:48:43 2020 +0800 fix: search titles containing ignored characters (#1395) * fix: search titles containing ignored characters * fix * add default value * add test * fix test Co-authored-by: Koy <[email protected]> commit 58fbca0 Author: Snyk bot <[email protected]> Date: Thu Nov 5 03:04:19 2020 +0200 fix: packages/docsify-server-renderer/package.json & packages/docsify-server-renderer/package-lock.json to reduce vulnerabilities (#1418) The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/SNYK-JS-DOMPURIFY-1035544
1 parent a5a431f commit 4e5dae7

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

packages/docsify-server-renderer/package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/docsify-server-renderer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"dependencies": {
1818
"debug": "^4.3.0",
1919
"docsify": "^4.11.6",
20-
"dompurify": "^2.1.1",
20+
"dompurify": "^2.2.2",
2121
"node-fetch": "^2.6.0",
2222
"resolve-pathname": "^3.0.0"
2323
}

src/plugins/search/search.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export function genIndex(path, content = '', router, depth) {
8383
const slugify = window.Docsify.slugify;
8484
const index = {};
8585
let slug;
86+
let title = '';
8687

8788
tokens.forEach(token => {
8889
if (token.type === 'heading' && token.depth <= depth) {
@@ -94,7 +95,16 @@ export function genIndex(path, content = '', router, depth) {
9495
slug = router.toURL(path, { id: slugify(escapeHtml(token.text)) });
9596
}
9697

97-
index[slug] = { slug, title: str, body: '' };
98+
if (str) {
99+
title = str
100+
.replace(/<!-- {docsify-ignore} -->/, '')
101+
.replace(/{docsify-ignore}/, '')
102+
.replace(/<!-- {docsify-ignore-all} -->/, '')
103+
.replace(/{docsify-ignore-all}/, '')
104+
.trim();
105+
}
106+
107+
index[slug] = { slug, title: title, body: '' };
98108
} else {
99109
if (!slug) {
100110
return;

test/e2e/search.test.js

+38
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,42 @@ describe('Search Plugin Tests', function() {
3535
await page.fill('input[type=search]', 'test');
3636
await expect(page).toEqualText('.results-panel h2', 'Test Page');
3737
});
38+
39+
test('search ignore title', async () => {
40+
const docsifyInitConfig = {
41+
markdown: {
42+
homepage: `
43+
# Hello World
44+
45+
This is the homepage.
46+
`,
47+
sidebar: `
48+
- [Home page](/)
49+
- [GitHub Pages](github)
50+
`,
51+
},
52+
routes: {
53+
'/github.md': `
54+
# GitHub Pages
55+
56+
This is the GitHub Pages.
57+
58+
## GitHub Pages ignore1 <!-- {docsify-ignore} -->
59+
60+
There're three places to populate your docs for your Github repository1.
61+
62+
## GitHub Pages ignore2 {docsify-ignore}
63+
64+
There're three places to populate your docs for your Github repository2.
65+
`,
66+
},
67+
scriptURLs: ['/lib/plugins/search.min.js'],
68+
};
69+
await docsifyInit(docsifyInitConfig);
70+
await page.fill('input[type=search]', 'repository1');
71+
await expect(page).toEqualText('.results-panel h2', 'GitHub Pages ignore1');
72+
await page.click('.clear-button');
73+
await page.fill('input[type=search]', 'repository2');
74+
await expect(page).toEqualText('.results-panel h2', 'GitHub Pages ignore2');
75+
});
3876
});

0 commit comments

Comments
 (0)