Skip to content

Commit

Permalink
feat(v2): Add themeConfig.noIndex option facebook#3528
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzahamidi committed Oct 11, 2020
1 parent 9c961a6 commit 42034fa
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function Layout(props: Props): JSX.Element {
themeConfig: {image: defaultImage, metadatas},
url: siteUrl,
titleDelimiter,
noIndex,
} = siteConfig;
const {
children,
Expand Down Expand Up @@ -66,6 +67,7 @@ function Layout(props: Props): JSX.Element {
<meta name="twitter:image:alt" content={`Image for ${metaTitle}`} />
)}
{permalink && <meta property="og:url" content={siteUrl + permalink} />}
{noIndex && <meta name="robots" content="noindex" />}
<meta name="twitter:card" content="summary_large_image" />
</Head>
<Head
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import {Props} from '@theme/DocItem';

function DocItem(props: Props): JSX.Element {
const {siteConfig = {}} = useDocusaurusContext();
const {url: siteUrl, title: siteTitle, titleDelimiter = ' | '} = siteConfig;
const {
url: siteUrl,
title: siteTitle,
titleDelimiter = ' | ',
noIndex,
} = siteConfig;
const {content: DocContent} = props;
const {metadata} = DocContent;
const {description, title, permalink} = metadata;
Expand Down Expand Up @@ -49,6 +54,7 @@ function DocItem(props: Props): JSX.Element {
<meta name="twitter:image:alt" content={`Image for ${title}`} />
)}
{permalink && <meta property="og:url" content={siteUrl + permalink} />}
{noIndex && <meta name="robots" content="noindex" />}
</Head>
<main className="col col-md-8 p-0">
<DocContent />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {

function DocItem(props: Props): JSX.Element {
const {siteConfig} = useDocusaurusContext();
const {url: siteUrl, title: siteTitle, titleDelimiter} = siteConfig;
const {url: siteUrl, title: siteTitle, titleDelimiter, noIndex} = siteConfig;
const {content: DocContent} = props;
const {metadata} = DocContent;
const {
Expand Down Expand Up @@ -77,6 +77,7 @@ function DocItem(props: Props): JSX.Element {
)}
{permalink && <meta property="og:url" content={siteUrl + permalink} />}
{permalink && <link rel="canonical" href={siteUrl + permalink} />}
{noIndex && <meta name="robots" content="noindex" />}
</Head>
<div
className={clsx('container padding-vert--lg', styles.docItemWrapper)}>
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus-theme-classic/src/theme/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function Layout(props: Props): JSX.Element {
themeConfig: {image: defaultImage, metadatas},
url: siteUrl,
titleDelimiter,
noIndex,
} = siteConfig;
const {
children,
Expand Down Expand Up @@ -75,6 +76,7 @@ function Layout(props: Props): JSX.Element {
)}
{permalink && <meta property="og:url" content={siteUrl + permalink} />}
{permalink && <link rel="canonical" href={siteUrl + permalink} />}
{noIndex && <meta name="robots" content="noindex" />}
<meta name="twitter:card" content="summary_large_image" />
</Head>

Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus-types/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface DocusaurusConfig {
}
)[];
titleDelimiter?: string;
noIndex?: boolean;
}

/**
Expand Down Expand Up @@ -122,6 +123,7 @@ export interface LoadContext {
outDir: string;
baseUrl: string;
ssrTemplate?: string;
noIndex?: boolean;
}

export interface InjectedHtmlTags {
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
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`

Boolean. If true, Docusaurus will politely ask crawlers and search engines to avoid indexing your site. This is done with a header tag and so only applies to docs and pages. Will not attempt to hide static resources. This is a best effort request. Malicious crawlers can and will still index your site.

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
1 change: 1 addition & 0 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
tagline: 'Build optimized websites quickly, focus on your content',
organizationName: 'facebook',
projectName: 'docusaurus',
noIndex: false,
baseUrl,
url: 'https://v2.docusaurus.io',
onBrokenLinks: isVersioningDisabled ? 'warn' : 'throw',
Expand Down

0 comments on commit 42034fa

Please sign in to comment.