Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Release] 4.13.1 #2101

Merged
merged 7 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
2 changes: 1 addition & 1 deletion docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![logo](_media/icon.svg)

# docsify <small>4.13.0</small>
# docsify <small>4.13.1</small>

> A magical documentation site generator.

Expand Down
30 changes: 9 additions & 21 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions docs/emoji.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:`
Expand Down Expand Up @@ -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:`
Expand Down Expand Up @@ -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:`
Expand Down
8 changes: 0 additions & 8 deletions docs/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ You will get `<a href="/demo/">link</a>`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
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docsify",
"version": "4.13.0",
"version": "4.13.1",
"description": "A magical documentation generator.",
"author": {
"name": "qingwei-li",
Expand Down
2 changes: 1 addition & 1 deletion packages/docsify-server-renderer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/docsify-server-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docsify-server-renderer",
"version": "4.13.0",
"version": "4.13.1",
"description": "docsify server renderer",
"author": {
"name": "qingwei-li",
Expand Down
1 change: 0 additions & 1 deletion src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default function (vm) {
catchPluginErrors: true,
cornerExternalLinkTarget: '_blank',
coverpage: '',
crossOriginLinks: [],
el: '#app',
executeScript: null,
ext: '.md',
Expand Down
11 changes: 0 additions & 11 deletions src/core/render/compiler/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)';
Expand Down
3 changes: 3 additions & 0 deletions src/core/render/emoji-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/core/router/history/hash.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}
});
Expand Down
11 changes: 3 additions & 8 deletions src/core/router/history/html5.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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' });
}
});
Expand Down
3 changes: 3 additions & 0 deletions src/core/util/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,8 @@ export function isExternal(url) {
) {
return true;
}
if (/^\/\\/.test(url)) {
return true;
}
return false;
}
4 changes: 1 addition & 3 deletions src/plugins/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '';
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/integration/__snapshots__/docs.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Docs Site coverpage renders and is unchanged 1`] = `
"<section class=\\"cover show\\" style=\\"background: linear-gradient(to left bottom, hsl(127, 100%, 85%) 0%,hsl(127, 100%, 85%) 100%)\\"><div class=\\"mask\\"></div><div class=\\"cover-main\\"><p><img src=\\"http://127.0.0.1:3001/_media/icon.svg\\" data-origin=\\"_media/icon.svg\\" alt=\\"logo\\"></p><h1 id=\\"docsify-4130\\"><a href=\\"#/?id=docsify-4130\\" data-id=\\"docsify-4130\\" class=\\"anchor\\"><span>docsify <small>4.13.0</small></span></a></h1><blockquote>
"<section class=\\"cover show\\" style=\\"background: linear-gradient(to left bottom, hsl(127, 100%, 85%) 0%,hsl(127, 100%, 85%) 100%)\\"><div class=\\"mask\\"></div><div class=\\"cover-main\\"><p><img src=\\"http://127.0.0.1:3001/_media/icon.svg\\" data-origin=\\"_media/icon.svg\\" alt=\\"logo\\"></p><h1 id=\\"docsify-4131\\"><a href=\\"#/?id=docsify-4131\\" data-id=\\"docsify-4131\\" class=\\"anchor\\"><span>docsify <small>4.13.1</small></span></a></h1><blockquote>
<p>A magical documentation site generator.</p></blockquote>
<ul><li>Simple and lightweight</li><li>No statically built html files</li><li>Multiple themes</li></ul><p><a href=\\"https://github.com/docsifyjs/docsify/\\" target=\\"_blank\\" rel=\\"noopener\\">GitHub</a>
<a href=\\"#/?id=docsify\\">Getting Started</a></p></div></section>"
Expand Down
12 changes: 12 additions & 0 deletions test/unit/core-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
Loading