Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): Add themeConfig.noIndex option #3528 #3573

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
hamzahamidi marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -122,6 +123,7 @@ export interface LoadContext {
outDir: string;
baseUrl: string;
ssrTemplate?: string;
noIndex?: boolean;
hamzahamidi marked this conversation as resolved.
Show resolved Hide resolved
}

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.
hamzahamidi marked this conversation as resolved.
Show resolved Hide resolved

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,
hamzahamidi marked this conversation as resolved.
Show resolved Hide resolved
baseUrl,
url: 'https://v2.docusaurus.io',
onBrokenLinks: isVersioningDisabled ? 'warn' : 'throw',
Expand Down