diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b3fa6ce..4078c4647 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## [4.13.1](https://github.com/docsifyjs/docsify/compare/v4.13.0...v4.13.1) (2023-06-24) + + +### Bug Fixes + +* enhancement of isExternal ([#2093](https://github.com/docsifyjs/docsify/issues/2093)) ([6a7d15b](https://github.com/docsifyjs/docsify/commit/6a7d15b1d5b93e19d3cf9a328cdbf5f1a166b5bd)) +* fix cross-origin links in history router mode ([#1967](https://github.com/docsifyjs/docsify/issues/1967)) ([2312fee](https://github.com/docsifyjs/docsify/commit/2312feef459211a8bcdcbf9164a9ffe051609b70)) +* genIndex error for search ([#1933](https://github.com/docsifyjs/docsify/issues/1933)) ([68d8735](https://github.com/docsifyjs/docsify/commit/68d873587c29d694ece466177984aa5fd739dd4b)) + + + # [4.13.0](https://github.com/docsifyjs/docsify/compare/v4.12.4...v4.13.0) (2022-10-26) diff --git a/docs/_coverpage.md b/docs/_coverpage.md index af2d706b5..a67b986f0 100644 --- a/docs/_coverpage.md +++ b/docs/_coverpage.md @@ -1,6 +1,6 @@ ![logo](_media/icon.svg) -# docsify 4.13.0 +# docsify 4.13.1 > A magical documentation site generator. diff --git a/docs/configuration.md b/docs/configuration.md index 3fdf2a61c..61c3a9b3e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -140,19 +140,6 @@ window.$docsify = { }; ``` -## crossOriginLinks - -- Type: `Array` - -When `routerMode: 'history'`, you may face cross-origin issues. See [#1379](https://github.com/docsifyjs/docsify/issues/1379). -In Markdown content, there is a simple way to solve it: see extends Markdown syntax `Cross-Origin link` in [helpers](helpers.md). - -```js -window.$docsify = { - crossOriginLinks: ['https://example.com/cross-origin-link'], -}; -``` - ## el - Type: `String` @@ -688,6 +675,7 @@ window.$docsify = { Define "virtual" routes that can provide content dynamically. A route is a map between the expected path, to either a string or a function. If the mapped value is a string, it is treated as markdown and parsed accordingly. If it is a function, it is expected to return markdown content. A route function receives up to three parameters: + 1. `route` - the path of the route that was requested (e.g. `/bar/baz`) 2. `matched` - the [`RegExpMatchArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) that was matched by the route (e.g. for `/bar/(.+)`, you get `['/bar/baz', 'baz']`) 3. `next` - this is a callback that you may call when your route function is async @@ -701,23 +689,23 @@ window.$docsify = { '/foo': '# Custom Markdown', // RegEx match w/ synchronous function - '/bar/(.*)': function(route, matched) { + '/bar/(.*)': function (route, matched) { return '# Custom Markdown'; }, // RegEx match w/ asynchronous function - '/baz/(.*)': function(route, matched, next) { - // Requires `fetch` polyfill for legacy browsers (https://github.github.io/fetch/) + '/baz/(.*)': function (route, matched, next) { + // Requires `fetch` polyfill for legacy browsers (https://github.github.io/fetch/) fetch('/api/users?id=12345') - .then(function(response) { + .then(function (response) { next('# Custom Markdown'); }) - .catch(function(err) { + .catch(function (err) { // Handle error... }); - } - } -} + }, + }, +}; ``` Other than strings, route functions can return a falsy value (`null` \ `undefined`) to indicate that they ignore the current request: diff --git a/docs/emoji.md b/docs/emoji.md index 4f198414c..3b562fadc 100644 --- a/docs/emoji.md +++ b/docs/emoji.md @@ -34,6 +34,8 @@ Below is a complete list of emoji shorthand codes. Docsify can be configured to :accept: `:accept:` +:accessibility: `:accessibility:` + :accordion: `:accordion:` :adhesive_bandage: `:adhesive_bandage:` @@ -920,6 +922,8 @@ Below is a complete list of emoji shorthand codes. Docsify can be configured to :department_store: `:department_store:` +:dependabot: `:dependabot:` + :derelict_house: `:derelict_house:` :desert: `:desert:` @@ -1238,6 +1242,8 @@ Below is a complete list of emoji shorthand codes. Docsify can be configured to :fishing_pole_and_fish: `:fishing_pole_and_fish:` +:fishsticks: `:fishsticks:` + :fist: `:fist:` :fist_left: `:fist_left:` diff --git a/docs/helpers.md b/docs/helpers.md index 6bd8a069d..a6fc95ea5 100644 --- a/docs/helpers.md +++ b/docs/helpers.md @@ -65,14 +65,6 @@ You will get `link`html. Do not worry, you can still set th [link](/demo ':disabled') ``` -## Cross-Origin link - -Only when you set both the `routerMode: 'history'` and `externalLinkTarget: '_self'`, you need to add this configuration for those Cross-Origin links. - -```md -[example.com](https://example.com/ ':crossorgin') -``` - ## GitHub Task Lists ```md diff --git a/package-lock.json b/package-lock.json index ca11673a6..198fd1cd2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "docsify", - "version": "4.13.0", + "version": "4.13.1", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 6c2dbbcc4..79868e2a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docsify", - "version": "4.13.0", + "version": "4.13.1", "description": "A magical documentation generator.", "author": { "name": "qingwei-li", diff --git a/packages/docsify-server-renderer/package-lock.json b/packages/docsify-server-renderer/package-lock.json index 0c077d906..eb7001bf3 100644 --- a/packages/docsify-server-renderer/package-lock.json +++ b/packages/docsify-server-renderer/package-lock.json @@ -1,6 +1,6 @@ { "name": "docsify-server-renderer", - "version": "4.13.0", + "version": "4.13.1", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/packages/docsify-server-renderer/package.json b/packages/docsify-server-renderer/package.json index 44e12cfac..3601f2a15 100644 --- a/packages/docsify-server-renderer/package.json +++ b/packages/docsify-server-renderer/package.json @@ -1,6 +1,6 @@ { "name": "docsify-server-renderer", - "version": "4.13.0", + "version": "4.13.1", "description": "docsify server renderer", "author": { "name": "qingwei-li", diff --git a/src/core/config.js b/src/core/config.js index 5dc9a3850..9a8bdb2f8 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -12,7 +12,6 @@ export default function (vm) { catchPluginErrors: true, cornerExternalLinkTarget: '_blank', coverpage: '', - crossOriginLinks: [], el: '#app', executeScript: null, ext: '.md', diff --git a/src/core/render/compiler/link.js b/src/core/render/compiler/link.js index fd8b81138..613101000 100644 --- a/src/core/render/compiler/link.js +++ b/src/core/render/compiler/link.js @@ -43,17 +43,6 @@ export const linkCompiler = ({ ); } - // special case to check crossorigin urls - if ( - config.crossorgin && - linkTarget === '_self' && - compilerClass.config.routerMode === 'history' - ) { - if (compilerClass.config.crossOriginLinks.indexOf(href) === -1) { - compilerClass.config.crossOriginLinks.push(href); - } - } - if (config.disabled) { attrs.push('disabled'); href = 'javascript:void(0)'; diff --git a/src/core/render/emoji-data.js b/src/core/render/emoji-data.js index c9494fca0..b065d0873 100644 --- a/src/core/render/emoji-data.js +++ b/src/core/render/emoji-data.js @@ -21,6 +21,7 @@ export default { "abc": "unicode/1f524.png?v8", "abcd": "unicode/1f521.png?v8", "accept": "unicode/1f251.png?v8", + "accessibility": "accessibility.png?v8", "accordion": "unicode/1fa97.png?v8", "adhesive_bandage": "unicode/1fa79.png?v8", "adult": "unicode/1f9d1.png?v8", @@ -464,6 +465,7 @@ export default { "deer": "unicode/1f98c.png?v8", "denmark": "unicode/1f1e9-1f1f0.png?v8", "department_store": "unicode/1f3ec.png?v8", + "dependabot": "dependabot.png?v8", "derelict_house": "unicode/1f3da.png?v8", "desert": "unicode/1f3dc.png?v8", "desert_island": "unicode/1f3dd.png?v8", @@ -623,6 +625,7 @@ export default { "fish": "unicode/1f41f.png?v8", "fish_cake": "unicode/1f365.png?v8", "fishing_pole_and_fish": "unicode/1f3a3.png?v8", + "fishsticks": "fishsticks.png?v8", "fist": "unicode/270a.png?v8", "fist_left": "unicode/1f91b.png?v8", "fist_oncoming": "unicode/1f44a.png?v8", diff --git a/src/core/router/history/hash.js b/src/core/router/history/hash.js index abb060f2f..05435d2c9 100644 --- a/src/core/router/history/hash.js +++ b/src/core/router/history/hash.js @@ -1,4 +1,4 @@ -import { noop } from '../../util/core'; +import { isExternal, noop } from '../../util/core'; import { on } from '../../util/dom'; import { endsWith } from '../../util/str'; import { parseQuery, cleanPath, replaceSlug } from '../util'; @@ -48,7 +48,7 @@ export class HashHistory extends History { on('click', e => { const el = e.target.tagName === 'A' ? e.target : e.target.parentNode; - if (el && el.tagName === 'A' && !/_blank/.test(el.target)) { + if (el && el.tagName === 'A' && !isExternal(el.href)) { navigating = true; } }); diff --git a/src/core/router/history/html5.js b/src/core/router/history/html5.js index eeadb1af1..1304d0628 100644 --- a/src/core/router/history/html5.js +++ b/src/core/router/history/html5.js @@ -1,4 +1,4 @@ -import { noop } from '../../util/core'; +import { isExternal, noop } from '../../util/core'; import { on } from '../../util/dom'; import { parseQuery, getPath } from '../util'; import { History } from './base'; @@ -24,15 +24,10 @@ export class HTML5History extends History { on('click', e => { const el = e.target.tagName === 'A' ? e.target : e.target.parentNode; - if (el && el.tagName === 'A' && !/_blank/.test(el.target)) { + if (el && el.tagName === 'A' && !isExternal(el.href)) { e.preventDefault(); const url = el.href; - // solve history.pushState cross-origin issue - if (this.config.crossOriginLinks.indexOf(url) !== -1) { - window.open(url, '_self'); - } else { - window.history.pushState({ key: url }, '', url); - } + window.history.pushState({ key: url }, '', url); cb({ event: e, source: 'navigate' }); } }); diff --git a/src/core/util/core.js b/src/core/util/core.js index 985a0e829..e1e585d53 100644 --- a/src/core/util/core.js +++ b/src/core/util/core.js @@ -96,5 +96,8 @@ export function isExternal(url) { ) { return true; } + if (/^\/\\/.test(url)) { + return true; + } return false; } diff --git a/src/plugins/search/search.js b/src/plugins/search/search.js index 3266b7bb4..f8d7cd3ab 100644 --- a/src/plugins/search/search.js +++ b/src/plugins/search/search.js @@ -128,9 +128,7 @@ export function genIndex(path, content = '', router, depth) { token.text = getTableData(token); token.text = getListData(token); - index[slug].body = index[slug].body - ? index[slug].body + token.text - : token.text; + index[slug].body = token.text || ''; } } }); diff --git a/test/integration/__snapshots__/docs.test.js.snap b/test/integration/__snapshots__/docs.test.js.snap index ae415aa46..002ae85bc 100644 --- a/test/integration/__snapshots__/docs.test.js.snap +++ b/test/integration/__snapshots__/docs.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Docs Site coverpage renders and is unchanged 1`] = ` -"

\\"logo\\"

docsify 4.13.0

+"

\\"logo\\"

docsify 4.13.1

A magical documentation site generator.

  • Simple and lightweight
  • No statically built html files
  • Multiple themes

GitHub Getting Started

" diff --git a/test/unit/core-util.test.js b/test/unit/core-util.test.js index 0ebbf7bbd..a6ff7d3ef 100644 --- a/test/unit/core-util.test.js +++ b/test/unit/core-util.test.js @@ -59,5 +59,17 @@ describe('core/util', () => { expect(result).toBeTruthy(); }); + + test('external url with one \\', () => { + const result = isExternal('/\\example.github.io/docsify/demo.md'); + + expect(result).toBeTruthy(); + }); + + test('external url with two \\', () => { + const result = isExternal('/\\\\example.github.io/docsify/demo.md'); + + expect(result).toBeTruthy(); + }); }); });