Squashed commit of the following:

commit a2ebb2192ac73211a8924111d736df9574abf61b
Author: 沈唁 <52o@qq52o.cn>
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 <koy@ko8e24.top>

commit 58fbca00ebd12f636c213d386761df9ebfb2bd4c
Author: Snyk bot <snyk-bot@snyk.io>
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
This commit is contained in:
John Hildenbiddle 2020-11-10 18:38:00 -06:00
parent a5a431f0c1
commit 4e5dae7d41
4 changed files with 53 additions and 5 deletions

View File

@ -45,9 +45,9 @@
}
},
"dompurify": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.1.1.tgz",
"integrity": "sha512-NijiNVkS/OL8mdQL1hUbCD6uty/cgFpmNiuFxrmJ5YPH2cXrPKIewoixoji56rbZ6XBPmtM8GA8/sf9unlSuwg=="
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.2.2.tgz",
"integrity": "sha512-BsGR4nDLaC5CNBnyT5I+d5pOeaoWvgVeg6Gq/aqmKYWMPR07131u60I80BvExLAJ0FQEIBQ1BTicw+C5+jOyrg=="
},
"good-listener": {
"version": "1.2.2",

View File

@ -17,7 +17,7 @@
"dependencies": {
"debug": "^4.3.0",
"docsify": "^4.11.6",
"dompurify": "^2.1.1",
"dompurify": "^2.2.2",
"node-fetch": "^2.6.0",
"resolve-pathname": "^3.0.0"
}

View File

@ -83,6 +83,7 @@ export function genIndex(path, content = '', router, depth) {
const slugify = window.Docsify.slugify;
const index = {};
let slug;
let title = '';
tokens.forEach(token => {
if (token.type === 'heading' && token.depth <= depth) {
@ -94,7 +95,16 @@ export function genIndex(path, content = '', router, depth) {
slug = router.toURL(path, { id: slugify(escapeHtml(token.text)) });
}
index[slug] = { slug, title: str, body: '' };
if (str) {
title = str
.replace(/<!-- {docsify-ignore} -->/, '')
.replace(/{docsify-ignore}/, '')
.replace(/<!-- {docsify-ignore-all} -->/, '')
.replace(/{docsify-ignore-all}/, '')
.trim();
}
index[slug] = { slug, title: title, body: '' };
} else {
if (!slug) {
return;

View File

@ -35,4 +35,42 @@ describe('Search Plugin Tests', function() {
await page.fill('input[type=search]', 'test');
await expect(page).toEqualText('.results-panel h2', 'Test Page');
});
test('search ignore title', async () => {
const docsifyInitConfig = {
markdown: {
homepage: `
# Hello World
This is the homepage.
`,
sidebar: `
- [Home page](/)
- [GitHub Pages](github)
`,
},
routes: {
'/github.md': `
# GitHub Pages
This is the GitHub Pages.
## GitHub Pages ignore1 <!-- {docsify-ignore} -->
There're three places to populate your docs for your Github repository1.
## GitHub Pages ignore2 {docsify-ignore}
There're three places to populate your docs for your Github repository2.
`,
},
scriptURLs: ['/lib/plugins/search.min.js'],
};
await docsifyInit(docsifyInitConfig);
await page.fill('input[type=search]', 'repository1');
await expect(page).toEqualText('.results-panel h2', 'GitHub Pages ignore1');
await page.click('.clear-button');
await page.fill('input[type=search]', 'repository2');
await expect(page).toEqualText('.results-panel h2', 'GitHub Pages ignore2');
});
});