Skip to content

Commit bf20ea1

Browse files
authored
Merge branch 'develop' into fix-1154
2 parents 10b1fc3 + 1a64dc8 commit bf20ea1

File tree

5 files changed

+53
-25
lines changed

5 files changed

+53
-25
lines changed

docs/configuration.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ You can configure Docsify by defining `window.$docsify` as an object:
1212
</script>
1313
```
1414

15-
The config can also be defined as a function, in which case the first arg is the Docsify `vm` instance. The function should return a config object. This can be useful for referencing `vm` in places like the markdown configuration:
15+
The config can also be defined as a function, in which case the first argument is the Docsify `vm` instance. The function should return a config object. This can be useful for referencing `vm` in places like the markdown configuration:
1616

1717
```html
1818
<script>
@@ -35,7 +35,7 @@ The config can also be defined as a function, in which case the first arg is the
3535
- Type: `String`
3636
- Default: `#app`
3737

38-
The DOM element to be mounted on initialization. It can be a CSS selector string or an actual HTMLElement.
38+
The DOM element to be mounted on initialization. It can be a CSS selector string or an actual [HTMLElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement).
3939

4040
```js
4141
window.$docsify = {
@@ -48,7 +48,7 @@ window.$docsify = {
4848
- Type: `String`
4949
- Default: `null`
5050

51-
Configure the repository url or a string of `username/repo` can add the [GitHub Corner](http://tholman.com/github-corners/) widget in the top right corner of the site.
51+
Configure the repository url, or a string of `username/repo` can add the [GitHub Corner](http://tholman.com/github-corners/) widget in the top right corner of the site.
5252

5353
```js
5454
window.$docsify = {
@@ -76,7 +76,7 @@ window.$docsify = {
7676
- Type: `Boolean|String`
7777
- Default: `false`
7878

79-
Loads navbar from the Markdown file `_navbar.md` if **true**, or else from the path specified.
79+
Loads navbar from the Markdown file `_navbar.md` if **true**, else loads it from the path specified.
8080

8181
```js
8282
window.$docsify = {
@@ -93,7 +93,7 @@ window.$docsify = {
9393
- Type: `Boolean|String`
9494
- Default: `false`
9595

96-
Loads sidebar from the Markdown file `_sidebar.md` if **true**, or else from the path specified.
96+
Loads sidebar from the Markdown file `_sidebar.md` if **true**, else loads it from the path specified.
9797

9898
```js
9999
window.$docsify = {
@@ -110,7 +110,7 @@ window.$docsify = {
110110
- Type : `Boolean`
111111
- Default: `true`
112112

113-
This option will completely hide your sidebar and wont render any content of the side even .
113+
This option will completely hide your sidebar and won't render any content on the side.
114114

115115
```js
116116
window.$docsify = {
@@ -149,7 +149,7 @@ window.$docsify = {
149149
- Type: `String`
150150
- Default: `README.md`
151151

152-
`README.md` in your docs folder will be treated as homepage for your website, but sometimes you may need to serve another file as your homepage.
152+
`README.md` in your docs folder will be treated as the homepage for your website, but sometimes you may need to serve another file as your homepage.
153153

154154
```js
155155
window.$docsify = {
@@ -196,7 +196,7 @@ window.$docsify = {
196196
- Type: `Boolean`
197197
- Default: `false`
198198

199-
If **true** links are relative to the current context.
199+
If **true**, links are relative to the current context.
200200

201201
For example, the directory structure is as follows:
202202

@@ -260,7 +260,7 @@ window.$docsify = {
260260

261261
- Type: `String`
262262

263-
Website logo as it appears in the sidebar, you can resize by CSS.
263+
Website logo as it appears in the sidebar. You can resize it by using CSS.
264264

265265
```js
266266
window.$docsify = {
@@ -367,7 +367,7 @@ window.$docsify = {
367367

368368
- type: `Boolean`
369369

370-
If `loadSidebar` and `autoHeader` are both enabled, for each link in `_sidebar.md`, prepend a header to the page before converting it to html. Compare [#78](https://github.com/docsifyjs/docsify/issues/78).
370+
If `loadSidebar` and `autoHeader` are both enabled, for each link in `_sidebar.md`, prepend a header to the page before converting it to HTML. Compare [#78](https://github.com/docsifyjs/docsify/issues/78).
371371

372372
```js
373373
window.$docsify = {
@@ -474,7 +474,7 @@ window.$docsify = {
474474
- type: `String`
475475
- default: `noopener`
476476

477-
Default `'noopener'` (no opener) prevents the newly opened external page (when [externalLinkTarget](#externallinktarget) is `'_blank'`) from having the ability to control our page. No `rel` is set when its not `'_blank'`. See [this post](https://mathiasbynens.github.io/rel-noopener/) for more information about why you may want to use this option.
477+
Default `'noopener'` (no opener) prevents the newly opened external page (when [externalLinkTarget](#externallinktarget) is `'_blank'`) from having the ability to control our page. No `rel` is set when it's not `'_blank'`. See [this post](https://mathiasbynens.github.io/rel-noopener/) for more information about why you may want to use this option.
478478

479479
```js
480480
window.$docsify = {
@@ -557,13 +557,13 @@ window.$docsify = {
557557

558558
- type: `Array<string>`
559559

560-
List of languages that will fallback to the default language when a page is request and didn't exists for the given local.
560+
List of languages that will fallback to the default language when a page is requested and it doesn't exist for the given local.
561561

562562
Example:
563563

564-
- try to fetch the page of `/de/overview`. If this page exists, it'll be displayed
565-
- then try to fetch the default page `/overview` (depending on the default language). If this page exists, it'll be displayed
566-
- then display 404 page.
564+
- try to fetch the page of `/de/overview`. If this page exists, it'll be displayed.
565+
- then try to fetch the default page `/overview` (depending on the default language). If this page exists, it'll be displayed.
566+
- then display the 404 page.
567567

568568
```js
569569
window.$docsify = {
@@ -583,7 +583,7 @@ window.$docsify = {
583583
};
584584
```
585585

586-
Load the customised path of the 404 page:
586+
Load the customized path of the 404 page:
587587

588588
```js
589589
window.$docsify = {

docs/plugins.md

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ By default, the hyperlink on the current page is recognized and the content is s
4444
// To avoid search index collision
4545
// between multiple websites under the same domain
4646
namespace: 'website-1',
47+
48+
// Use different indexes for path prefixes (namespaces).
49+
// NOTE: Only works in 'auto' mode.
50+
//
51+
// When initialiazing an index, we look for the first path from the sidebar.
52+
// If it matches the prefix from the list, we switch to the corresponding index.
53+
pathNamespaces: ['/zh-cn', '/ru-ru', '/ru-ru/v1'],
54+
55+
// You can provide a regexp to match prefixes. In this case,
56+
// the matching substring will be used to identify the index
57+
pathNamespaces: /^(\/(zh-cn|ru-ru))?(\/(v1|v2))?/
4758
}
4859
}
4960
</script>

index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
'/de-de/': 'Suche',
5252
'/zh-cn/': '搜索',
5353
'/': 'Search'
54-
}
54+
},
55+
pathNamespaces: ['/zh-cn', '/de-de', '/ru-ru', '/es']
5556
},
5657
plugins: [
5758
function (hook, vm) {

src/plugins/search/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const CONFIG = {
1010
maxAge: 86400000, // 1 day
1111
hideOtherSidebarContent: false,
1212
namespace: undefined,
13+
pathNamespaces: undefined,
1314
};
1415

1516
const install = function(hook, vm) {
@@ -27,6 +28,7 @@ const install = function(hook, vm) {
2728
CONFIG.hideOtherSidebarContent =
2829
opts.hideOtherSidebarContent || CONFIG.hideOtherSidebarContent;
2930
CONFIG.namespace = opts.namespace || CONFIG.namespace;
31+
CONFIG.pathNamespaces = opts.pathNamespaces || CONFIG.pathNamespaces;
3032
}
3133

3234
const isAuto = CONFIG.paths === 'auto';

src/plugins/search/search.js

+22-8
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,29 @@ export function search(query) {
198198

199199
export function init(config, vm) {
200200
const isAuto = config.paths === 'auto';
201+
const paths = isAuto ? getAllPaths(vm.router) : config.paths;
202+
203+
let namespaceSuffix = '';
204+
205+
// only in auto mode
206+
if (isAuto && config.pathNamespaces) {
207+
const path = paths[0];
208+
209+
if (Array.isArray(config.pathNamespaces)) {
210+
namespaceSuffix =
211+
config.pathNamespaces.find(prefix => path.startsWith(prefix)) ||
212+
namespaceSuffix;
213+
} else if (config.pathNamespaces instanceof RegExp) {
214+
const matches = path.match(config.pathNamespaces);
215+
216+
if (matches) {
217+
namespaceSuffix = matches[0];
218+
}
219+
}
220+
}
201221

202-
const expireKey = resolveExpireKey(config.namespace);
203-
const indexKey = resolveIndexKey(config.namespace);
222+
const expireKey = resolveExpireKey(config.namespace) + namespaceSuffix;
223+
const indexKey = resolveIndexKey(config.namespace) + namespaceSuffix;
204224

205225
const isExpired = localStorage.getItem(expireKey) < Date.now();
206226

@@ -212,15 +232,9 @@ export function init(config, vm) {
212232
return;
213233
}
214234

215-
const paths = isAuto ? getAllPaths(vm.router) : config.paths;
216235
const len = paths.length;
217236
let count = 0;
218237

219-
// Fix search error when exist translations documents
220-
if (INDEXS !== null && !INDEXS[paths[0]]) {
221-
INDEXS = {};
222-
}
223-
224238
paths.forEach(path => {
225239
if (INDEXS[path]) {
226240
return count++;

0 commit comments

Comments
 (0)