Skip to content

Commit

Permalink
Merge branch 'develop' into fix-1154
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records authored Jul 26, 2020
2 parents 10b1fc3 + 1a64dc8 commit bf20ea1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 25 deletions.
32 changes: 16 additions & 16 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You can configure Docsify by defining `window.$docsify` as an object:
</script>
```

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:
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:

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

The DOM element to be mounted on initialization. It can be a CSS selector string or an actual HTMLElement.
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).

```js
window.$docsify = {
Expand All @@ -48,7 +48,7 @@ window.$docsify = {
- Type: `String`
- Default: `null`

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.
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.

```js
window.$docsify = {
Expand Down Expand Up @@ -76,7 +76,7 @@ window.$docsify = {
- Type: `Boolean|String`
- Default: `false`

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

```js
window.$docsify = {
Expand All @@ -93,7 +93,7 @@ window.$docsify = {
- Type: `Boolean|String`
- Default: `false`

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

```js
window.$docsify = {
Expand All @@ -110,7 +110,7 @@ window.$docsify = {
- Type : `Boolean`
- Default: `true`

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

```js
window.$docsify = {
Expand Down Expand Up @@ -149,7 +149,7 @@ window.$docsify = {
- Type: `String`
- Default: `README.md`

`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.
`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.

```js
window.$docsify = {
Expand Down Expand Up @@ -196,7 +196,7 @@ window.$docsify = {
- Type: `Boolean`
- Default: `false`

If **true** links are relative to the current context.
If **true**, links are relative to the current context.

For example, the directory structure is as follows:

Expand Down Expand Up @@ -260,7 +260,7 @@ window.$docsify = {

- Type: `String`

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

```js
window.$docsify = {
Expand Down Expand Up @@ -367,7 +367,7 @@ window.$docsify = {

- type: `Boolean`

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).
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).

```js
window.$docsify = {
Expand Down Expand Up @@ -474,7 +474,7 @@ window.$docsify = {
- type: `String`
- default: `noopener`

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.
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.

```js
window.$docsify = {
Expand Down Expand Up @@ -557,13 +557,13 @@ window.$docsify = {

- type: `Array<string>`

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

Example:

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

```js
window.$docsify = {
Expand All @@ -583,7 +583,7 @@ window.$docsify = {
};
```

Load the customised path of the 404 page:
Load the customized path of the 404 page:

```js
window.$docsify = {
Expand Down
11 changes: 11 additions & 0 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ By default, the hyperlink on the current page is recognized and the content is s
// To avoid search index collision
// between multiple websites under the same domain
namespace: 'website-1',
// Use different indexes for path prefixes (namespaces).
// NOTE: Only works in 'auto' mode.
//
// When initialiazing an index, we look for the first path from the sidebar.
// If it matches the prefix from the list, we switch to the corresponding index.
pathNamespaces: ['/zh-cn', '/ru-ru', '/ru-ru/v1'],
// You can provide a regexp to match prefixes. In this case,
// the matching substring will be used to identify the index
pathNamespaces: /^(\/(zh-cn|ru-ru))?(\/(v1|v2))?/
}
}
</script>
Expand Down
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
'/de-de/': 'Suche',
'/zh-cn/': '搜索',
'/': 'Search'
}
},
pathNamespaces: ['/zh-cn', '/de-de', '/ru-ru', '/es']
},
plugins: [
function (hook, vm) {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const CONFIG = {
maxAge: 86400000, // 1 day
hideOtherSidebarContent: false,
namespace: undefined,
pathNamespaces: undefined,
};

const install = function(hook, vm) {
Expand All @@ -27,6 +28,7 @@ const install = function(hook, vm) {
CONFIG.hideOtherSidebarContent =
opts.hideOtherSidebarContent || CONFIG.hideOtherSidebarContent;
CONFIG.namespace = opts.namespace || CONFIG.namespace;
CONFIG.pathNamespaces = opts.pathNamespaces || CONFIG.pathNamespaces;
}

const isAuto = CONFIG.paths === 'auto';
Expand Down
30 changes: 22 additions & 8 deletions src/plugins/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,29 @@ export function search(query) {

export function init(config, vm) {
const isAuto = config.paths === 'auto';
const paths = isAuto ? getAllPaths(vm.router) : config.paths;

let namespaceSuffix = '';

// only in auto mode
if (isAuto && config.pathNamespaces) {
const path = paths[0];

if (Array.isArray(config.pathNamespaces)) {
namespaceSuffix =
config.pathNamespaces.find(prefix => path.startsWith(prefix)) ||
namespaceSuffix;
} else if (config.pathNamespaces instanceof RegExp) {
const matches = path.match(config.pathNamespaces);

if (matches) {
namespaceSuffix = matches[0];
}
}
}

const expireKey = resolveExpireKey(config.namespace);
const indexKey = resolveIndexKey(config.namespace);
const expireKey = resolveExpireKey(config.namespace) + namespaceSuffix;
const indexKey = resolveIndexKey(config.namespace) + namespaceSuffix;

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

Expand All @@ -212,15 +232,9 @@ export function init(config, vm) {
return;
}

const paths = isAuto ? getAllPaths(vm.router) : config.paths;
const len = paths.length;
let count = 0;

// Fix search error when exist translations documents
if (INDEXS !== null && !INDEXS[paths[0]]) {
INDEXS = {};
}

paths.forEach(path => {
if (INDEXS[path]) {
return count++;
Expand Down

0 comments on commit bf20ea1

Please sign in to comment.