Skip to content

Commit

Permalink
feat(v2): Add themeConfig.noIndex option #3528 (#3573)
Browse files Browse the repository at this point in the history
* feat(v2): Add themeConfig.noIndex option #3528

* feat(v2): Add themeConfig.noIndex optionthrough ssrTemplate

* feat(v2): Include themeConfig.noIndex in CLI migration v1 to v2

* feat(v2): Remove themeConfig.noIndex from env dev
  • Loading branch information
hamzahamidi authored Oct 14, 2020
1 parent e5d9cdc commit e0c644e
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
baseUrl: '/',
organizationName: 'facebook',
projectName: 'docusaurus',
noIndex: true,
scripts: [
'https://buttons.github.io/buttons.js',
'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const siteConfig = {
organizationName: 'facebook',
projectName: 'docusaurus',
cname: 'docusaurus.io',
noIndex: false,
noIndex: true,
users,
editUrl: 'https://github.com/facebook/docusaurus/edit/master/docs/',
headerLinks: [
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-migrate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export function createConfigFile({
baseUrl: siteConfig.baseUrl ?? '',
organizationName: siteConfig.organizationName,
projectName: siteConfig.projectName,
noIndex: siteConfig.noIndex,
scripts: siteConfig.scripts,
stylesheets: siteConfig.stylesheets,
favicon: siteConfig.favicon ?? '',
Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus-migrate/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface VersionTwoConfig {
url: string;
organizationName?: string;
projectName?: string;
noIndex?: boolean;
githubHost?: string;
onBrokenLinks: string;
plugins: Array<[string, {[key: string]: any}]>;
Expand Down Expand Up @@ -94,7 +95,7 @@ export type VersionOneConfig = {
defaultVersionShown?: string;
organizationName?: string;
projectName?: string;
noIndex?: string;
noIndex?: boolean;
headerLinks?: Array<any>;
headerIcon?: string;
favicon?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-types/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface DocusaurusConfig {
url: string;
onBrokenLinks: ReportingSeverity;
onDuplicateRoutes: ReportingSeverity;
noIndex: boolean;
organizationName?: string;
projectName?: string;
githubHost?: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus/src/client/serverEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default async function render(locals) {
onLinksCollected,
baseUrl,
ssrTemplate,
noIndex,
} = locals;
const location = routesLocation[locals.path];
await preload(routes, location);
Expand Down Expand Up @@ -101,6 +102,7 @@ export default async function render(locals) {
metaAttributes,
scripts,
stylesheets,
noIndex,
version: packageJson.version,
});

Expand Down
3 changes: 3 additions & 0 deletions packages/docusaurus/src/client/templates/ssr.html.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ 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" />
<% } %>
<%~ it.headTags %>
<% it.metaAttributes.forEach((metaAttribute) => { %>
<%~ metaAttribute %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Object {
"baseUrl": "/",
"customFields": Object {},
"favicon": "img/docusaurus.ico",
"noIndex": false,
"onBrokenLinks": "throw",
"onDuplicateRoutes": "warn",
"organizationName": "endiliey",
Expand Down
3 changes: 3 additions & 0 deletions packages/docusaurus/src/server/configValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const DEFAULT_CONFIG: Pick<
| 'customFields'
| 'themeConfig'
| 'titleDelimiter'
| 'noIndex'
> = {
onBrokenLinks: 'throw',
onDuplicateRoutes: 'warn',
Expand All @@ -33,6 +34,7 @@ export const DEFAULT_CONFIG: Pick<
customFields: {},
themeConfig: {},
titleDelimiter: '|',
noIndex: false,
};

const PluginSchema = Joi.alternatives().try(
Expand Down Expand Up @@ -94,6 +96,7 @@ const ConfigSchema = Joi.object({
clientModules: Joi.array().items(Joi.string()),
tagline: Joi.string().allow(''),
titleDelimiter: Joi.string().default('|'),
noIndex: Joi.bool().default(false),
});

// TODO move to @docusaurus/utils-validation
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus/src/webpack/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function createServerConfig({
preBodyTags,
postBodyTags,
ssrTemplate,
siteConfig: {noIndex},
} = props;
const config = createBaseConfig(props, true, minify);

Expand Down Expand Up @@ -72,6 +73,7 @@ export default function createServerConfig({
postBodyTags,
onLinksCollected,
ssrTemplate,
noIndex,
},
paths: ssgPaths,
}),
Expand Down
14 changes: 14 additions & 0 deletions website/docs/api/docusaurus.config.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ module.exports = {

## Optional fields

### `noIndex`

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

Example:

```js title="docusaurus.config.js"
module.exports = {
noIndex: true, // Defaults to false
};
```

### `onBrokenLinks`

- Type: `'ignore' | 'log' | 'warn' | 'error' | 'throw'`
Expand Down
1 change: 0 additions & 1 deletion website/docs/guides/migrating-from-v1-to-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ The following fields are all deprecated, you may remove from your configuration
- `markdownOptions` - We use MDX in v2 instead of Remarkable. Your markdown options have to be converted to Remark/Rehype plugins.
- `markdownPlugins` - We use MDX in v2 instead of Remarkable. Your markdown plugins have to be converted to Remark/Rehype plugins.
- `manifest`
- `noIndex`
- `onPageNav` - This is turned on by default now.
- `separateCss` - It can imported in the same manner as `custom.css` mentioned above.
- `scrollToTop`
Expand Down

0 comments on commit e0c644e

Please sign in to comment.