refactor(v2): various fixes (#3587)

* refactor(v2): various fixes

* Test
This commit is contained in:
Alexey Pyltsyn 2020-10-16 11:54:23 +03:00 committed by GitHub
parent 67136a77b8
commit bfefc46436
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 27 additions and 15 deletions

View file

@ -13,7 +13,7 @@ describe('isSamePath', () => {
});
test('should be true for compared path with trailing slash', () => {
expect(isSamePath('/docs', '/docs')).toBeTruthy();
expect(isSamePath('/docs', '/docs/')).toBeTruthy();
});
test('should be false for compared path with double trailing slash', () => {

View file

@ -60,7 +60,7 @@ export default function DocsVersionDropdownNavbarItem({
// We don't want to render a version dropdown with 0 or 1 item
// If we build the site with a single docs version (onlyIncludeVersions: ['1.0.0'])
// We'd rather render a buttonb instead of a dropdown
// We'd rather render a button instead of a dropdown
if (items.length <= 1) {
return undefined;
}

View file

@ -12,8 +12,8 @@ module.exports = `
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Docusaurus v<%= it.version %>">
<%if (it.noIndex) { %>
<meta name="robots" content="noindex" />
<% if (it.noIndex) { %>
<meta name="robots" content="noindex, nofollow" />
<% } %>
<%~ it.headTags %>
<% it.metaAttributes.forEach((metaAttribute) => { %>

View file

@ -896,7 +896,7 @@ const users = [
users.forEach((user) => {
if (!user.image || !user.image.startsWith('/img/users/')) {
throw new Error(
`Bad user site image = ${user.image}. The image should be hosted on Docusaurus site, in /static/img/users/ folder, and not use remote http or https urls`,
`Bad user site image = ${user.image}. The image should be hosted on Docusaurus site, in /static/img/users/ folder, and not use remote HTTP or HTTPS URLs`,
);
}
});

View file

@ -84,13 +84,13 @@ module.exports = {
- Type: `boolean`
This option adds `<meta name="robots" content="noindex">` in pages, to tell search engines to avoid indexing your site (more information [here](https://moz.com/learn/seo/robots-meta-directives)).
This option adds `<meta name="robots" content="noindex, nofollow">` in pages, to tell search engines to avoid indexing your site (more information [here](https://moz.com/learn/seo/robots-meta-directives)).
Example:
```js title="docusaurus.config.js"
module.exports = {
noIndex: true, // Defaults to false
noIndex: true, // Defaults to `false`
};
```

View file

@ -299,10 +299,11 @@ You may use them to return your webpack configures conditionally.
For example, this plugin below modify the webpack config to transpile `.foo` file.
```js {4-11} title="docusaurus-plugin/src/index.js"
```js title="docusaurus-plugin/src/index.js"
module.exports = function (context, options) {
return {
name: 'custom-docusaurus-plugin',
// highlight-start
configureWebpack(config, isServer, utils) {
const {getCacheLoader} = utils;
return {
@ -316,6 +317,7 @@ module.exports = function (context, options) {
},
};
},
// highlight-end
};
};
```
@ -326,14 +328,16 @@ We merge the Webpack configuration parts of plugins into the global Webpack conf
It is possible to specify the merge strategy. For example, if you want a webpack rule to be prepended instead of appended:
```js {4-11} title="docusaurus-plugin/src/index.js"
```js title="docusaurus-plugin/src/index.js"
module.exports = function (context, options) {
return {
name: 'custom-docusaurus-plugin',
configureWebpack(config, isServer, utils) {
return {
// highlight-start
mergeStrategy: {'module.rules': 'prepend'},
module: {rules: [myRuleToPrepend]},
// highlight-end
};
},
};
@ -433,10 +437,11 @@ interface HtmlTagObject {
Example:
```js {4-28} title="docusaurus-plugin/src/index.js"
```js title="docusaurus-plugin/src/index.js"
module.exports = function (context, options) {
return {
name: 'docusaurus-plugin',
// highlight-start
injectHtmlTags() {
return {
headTags: [
@ -460,6 +465,7 @@ module.exports = function (context, options) {
postBodyTags: [`<div> This is post body </div>`],
};
},
// highlight-end
};
};
```

View file

@ -190,11 +190,12 @@ You can add items to the navbar via `themeConfig.navbar.items`.
By default, Navbar items are regular links (internal or external).
```js {5-15} title="docusaurus.config.js"
```js title="docusaurus.config.js"
module.exports = {
// ...
themeConfig: {
navbar: {
// highlight-start
items: [
{
// Client-side routing, used for navigating within the website.
@ -220,6 +221,7 @@ module.exports = {
},
// ... other items
],
// highlight-end
},
// ...
},
@ -266,11 +268,12 @@ module.exports = {
If you want to link to a specific doc, this special navbar item type will render the link to the doc of the provided `docId`. It will get the class `navbar__link--active` as long as you browse a doc of the same sidebar.
```js {5-10} title="docusaurus.config.js"
```js title="docusaurus.config.js"
module.exports = {
themeConfig: {
navbar: {
items: [
// highlight-start
{
type: 'doc',
position: 'left',
@ -278,6 +281,7 @@ module.exports = {
label: 'Docs',
activeSidebarClassName: 'navbar__link--active',
},
// highlight-end
],
},
},
@ -314,17 +318,19 @@ module.exports = {
If you use docs with versioning, this special navbar item type will link to the active/browsed version of your doc (depends on the current url), and fallback to the latest version.
```js {5-10} title="docusaurus.config.js"
```js title="docusaurus.config.js"
module.exports = {
themeConfig: {
navbar: {
items: [
// highlight-start
{
type: 'docsVersion',
position: 'left',
// to: "/path // by default, link to active/latest version
// label: "label" // by default, show active/latest version label
},
// highlight-end
],
},
},

View file

@ -303,7 +303,7 @@ users.forEach((user) => {
(user.preview.startsWith('http') || user.preview.startsWith('//')))
) {
throw new Error(
`Bad user site image preview = ${user.preview}. The image should be hosted on Docusaurus site, and not use remote http or https urls`,
`Bad user site image preview = ${user.preview}. The image should be hosted on Docusaurus site, and not use remote HTTP or HTTPS URLs`,
);
}
});

View file

@ -4,7 +4,7 @@
"theme_color": "#2196f3",
"background_color": "#424242",
"display": "standalone",
"scope": "",
"scope": "./",
"start_url": "./index.html",
"icons": [
{