Skip to content

Commit

Permalink
feat(v2): Add themeConfig.noIndex optionthrough ssrTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzahamidi committed Oct 12, 2020
1 parent cb6fe8b commit a4a5503
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function Layout(props: Props): JSX.Element {
themeConfig: {image: defaultImage, metadatas},
url: siteUrl,
titleDelimiter,
noIndex,
} = siteConfig;
const {
children,
Expand Down Expand Up @@ -67,7 +66,6 @@ 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,12 +15,7 @@ import {Props} from '@theme/DocItem';

function DocItem(props: Props): JSX.Element {
const {siteConfig = {}} = useDocusaurusContext();
const {
url: siteUrl,
title: siteTitle,
titleDelimiter = ' | ',
noIndex,
} = siteConfig;
const {url: siteUrl, title: siteTitle, titleDelimiter = ' | '} = siteConfig;
const {content: DocContent} = props;
const {metadata} = DocContent;
const {description, title, permalink} = metadata;
Expand Down Expand Up @@ -54,7 +49,6 @@ 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, noIndex} = siteConfig;
const {url: siteUrl, title: siteTitle, titleDelimiter} = siteConfig;
const {content: DocContent} = props;
const {metadata} = DocContent;
const {
Expand Down Expand Up @@ -77,7 +77,6 @@ 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: 0 additions & 2 deletions packages/docusaurus-theme-classic/src/theme/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function Layout(props: Props): JSX.Element {
themeConfig: {image: defaultImage, metadatas},
url: siteUrl,
titleDelimiter,
noIndex,
} = siteConfig;
const {
children,
Expand Down Expand Up @@ -76,7 +75,6 @@ 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
3 changes: 1 addition & 2 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 Expand Up @@ -51,7 +52,6 @@ export interface DocusaurusConfig {
}
)[];
titleDelimiter?: string;
noIndex?: boolean;
}

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

export interface InjectedHtmlTags {
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Docusaurus">
<title><%= htmlWebpackPlugin.options.title %></title>
<%if (htmlWebpackPlugin.options.noIndex) { %>
<meta name="robots" content="noindex" />
<% } %>
<%= htmlWebpackPlugin.options.headTags %>
<%= htmlWebpackPlugin.tags.headTags %>
</head>
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
1 change: 1 addition & 0 deletions packages/docusaurus/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default async function start(
inject: false,
filename: 'index.html',
title: siteConfig.title,
noIndex: siteConfig.noIndex,
headTags,
preBodyTags,
postBodyTags,
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
2 changes: 1 addition & 1 deletion website/docs/api/docusaurus.config.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module.exports = {

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

Expand Down
1 change: 0 additions & 1 deletion website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ 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 a4a5503

Please sign in to comment.