mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-29 18:27:56 +02:00
refactor(v2): various fixes (#3587)
* refactor(v2): various fixes * Test
This commit is contained in:
parent
67136a77b8
commit
bfefc46436
9 changed files with 27 additions and 15 deletions
|
@ -13,7 +13,7 @@ describe('isSamePath', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should be true for compared path with trailing slash', () => {
|
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', () => {
|
test('should be false for compared path with double trailing slash', () => {
|
||||||
|
|
|
@ -60,7 +60,7 @@ export default function DocsVersionDropdownNavbarItem({
|
||||||
|
|
||||||
// We don't want to render a version dropdown with 0 or 1 item
|
// 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'])
|
// 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) {
|
if (items.length <= 1) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@ module.exports = `
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta name="generator" content="Docusaurus v<%= it.version %>">
|
<meta name="generator" content="Docusaurus v<%= it.version %>">
|
||||||
<%if (it.noIndex) { %>
|
<% if (it.noIndex) { %>
|
||||||
<meta name="robots" content="noindex" />
|
<meta name="robots" content="noindex, nofollow" />
|
||||||
<% } %>
|
<% } %>
|
||||||
<%~ it.headTags %>
|
<%~ it.headTags %>
|
||||||
<% it.metaAttributes.forEach((metaAttribute) => { %>
|
<% it.metaAttributes.forEach((metaAttribute) => { %>
|
||||||
|
|
|
@ -896,7 +896,7 @@ const users = [
|
||||||
users.forEach((user) => {
|
users.forEach((user) => {
|
||||||
if (!user.image || !user.image.startsWith('/img/users/')) {
|
if (!user.image || !user.image.startsWith('/img/users/')) {
|
||||||
throw new Error(
|
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`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -84,13 +84,13 @@ module.exports = {
|
||||||
|
|
||||||
- Type: `boolean`
|
- 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:
|
Example:
|
||||||
|
|
||||||
```js title="docusaurus.config.js"
|
```js title="docusaurus.config.js"
|
||||||
module.exports = {
|
module.exports = {
|
||||||
noIndex: true, // Defaults to false
|
noIndex: true, // Defaults to `false`
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -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.
|
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) {
|
module.exports = function (context, options) {
|
||||||
return {
|
return {
|
||||||
name: 'custom-docusaurus-plugin',
|
name: 'custom-docusaurus-plugin',
|
||||||
|
// highlight-start
|
||||||
configureWebpack(config, isServer, utils) {
|
configureWebpack(config, isServer, utils) {
|
||||||
const {getCacheLoader} = utils;
|
const {getCacheLoader} = utils;
|
||||||
return {
|
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:
|
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) {
|
module.exports = function (context, options) {
|
||||||
return {
|
return {
|
||||||
name: 'custom-docusaurus-plugin',
|
name: 'custom-docusaurus-plugin',
|
||||||
configureWebpack(config, isServer, utils) {
|
configureWebpack(config, isServer, utils) {
|
||||||
return {
|
return {
|
||||||
|
// highlight-start
|
||||||
mergeStrategy: {'module.rules': 'prepend'},
|
mergeStrategy: {'module.rules': 'prepend'},
|
||||||
module: {rules: [myRuleToPrepend]},
|
module: {rules: [myRuleToPrepend]},
|
||||||
|
// highlight-end
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -433,10 +437,11 @@ interface HtmlTagObject {
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```js {4-28} title="docusaurus-plugin/src/index.js"
|
```js title="docusaurus-plugin/src/index.js"
|
||||||
module.exports = function (context, options) {
|
module.exports = function (context, options) {
|
||||||
return {
|
return {
|
||||||
name: 'docusaurus-plugin',
|
name: 'docusaurus-plugin',
|
||||||
|
// highlight-start
|
||||||
injectHtmlTags() {
|
injectHtmlTags() {
|
||||||
return {
|
return {
|
||||||
headTags: [
|
headTags: [
|
||||||
|
@ -460,6 +465,7 @@ module.exports = function (context, options) {
|
||||||
postBodyTags: [`<div> This is post body </div>`],
|
postBodyTags: [`<div> This is post body </div>`],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
// highlight-end
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
|
@ -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).
|
By default, Navbar items are regular links (internal or external).
|
||||||
|
|
||||||
```js {5-15} title="docusaurus.config.js"
|
```js title="docusaurus.config.js"
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// ...
|
// ...
|
||||||
themeConfig: {
|
themeConfig: {
|
||||||
navbar: {
|
navbar: {
|
||||||
|
// highlight-start
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
// Client-side routing, used for navigating within the website.
|
// Client-side routing, used for navigating within the website.
|
||||||
|
@ -220,6 +221,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
// ... other items
|
// ... 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.
|
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 = {
|
module.exports = {
|
||||||
themeConfig: {
|
themeConfig: {
|
||||||
navbar: {
|
navbar: {
|
||||||
items: [
|
items: [
|
||||||
|
// highlight-start
|
||||||
{
|
{
|
||||||
type: 'doc',
|
type: 'doc',
|
||||||
position: 'left',
|
position: 'left',
|
||||||
|
@ -278,6 +281,7 @@ module.exports = {
|
||||||
label: 'Docs',
|
label: 'Docs',
|
||||||
activeSidebarClassName: 'navbar__link--active',
|
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.
|
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 = {
|
module.exports = {
|
||||||
themeConfig: {
|
themeConfig: {
|
||||||
navbar: {
|
navbar: {
|
||||||
items: [
|
items: [
|
||||||
|
// highlight-start
|
||||||
{
|
{
|
||||||
type: 'docsVersion',
|
type: 'docsVersion',
|
||||||
position: 'left',
|
position: 'left',
|
||||||
// to: "/path // by default, link to active/latest version
|
// to: "/path // by default, link to active/latest version
|
||||||
// label: "label" // by default, show active/latest version label
|
// label: "label" // by default, show active/latest version label
|
||||||
},
|
},
|
||||||
|
// highlight-end
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -303,7 +303,7 @@ users.forEach((user) => {
|
||||||
(user.preview.startsWith('http') || user.preview.startsWith('//')))
|
(user.preview.startsWith('http') || user.preview.startsWith('//')))
|
||||||
) {
|
) {
|
||||||
throw new Error(
|
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`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"theme_color": "#2196f3",
|
"theme_color": "#2196f3",
|
||||||
"background_color": "#424242",
|
"background_color": "#424242",
|
||||||
"display": "standalone",
|
"display": "standalone",
|
||||||
"scope": "",
|
"scope": "./",
|
||||||
"start_url": "./index.html",
|
"start_url": "./index.html",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue