From 0a2ab30c306e148394762c5f4db4ab3615c7bfc6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Lorber?=
Date: Fri, 19 Aug 2022 16:47:28 +0200
Subject: [PATCH] fix(core): allow overriding ssr/dev template meta tags
(#7952)
---
.../src/client/SiteMetadataDefaults.tsx | 10 +++++++++-
.../webpack/templates/index.html.template.ejs | 1 -
.../src/webpack/templates/ssr.html.template.ts | 6 +-----
.../_dogfooding/_pages tests/head-metadata.md | 17 +++++++++++++++++
website/_dogfooding/_pages tests/index.md | 1 +
website/docs/api/docusaurus.config.js.md | 6 +-----
6 files changed, 29 insertions(+), 12 deletions(-)
create mode 100644 website/_dogfooding/_pages tests/head-metadata.md
diff --git a/packages/docusaurus/src/client/SiteMetadataDefaults.tsx b/packages/docusaurus/src/client/SiteMetadataDefaults.tsx
index e3ba631fbbe5..1f49959d3536 100644
--- a/packages/docusaurus/src/client/SiteMetadataDefaults.tsx
+++ b/packages/docusaurus/src/client/SiteMetadataDefaults.tsx
@@ -12,7 +12,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
export default function SiteMetadataDefaults(): JSX.Element {
const {
- siteConfig: {favicon, title},
+ siteConfig: {favicon, title, noIndex},
i18n: {currentLocale, localeConfigs},
} = useDocusaurusContext();
const faviconUrl = useBaseUrl(favicon);
@@ -20,9 +20,17 @@ export default function SiteMetadataDefaults(): JSX.Element {
return (
+ {/*
+ charSet + generator are handled in the html templates
+ See https://github.com/facebook/docusaurus/pull/7952
+
+
+ */}
{title}
+
+ {noIndex && }
{favicon && }
);
diff --git a/packages/docusaurus/src/webpack/templates/index.html.template.ejs b/packages/docusaurus/src/webpack/templates/index.html.template.ejs
index 233efa98a3f4..ee6270b0e4e6 100644
--- a/packages/docusaurus/src/webpack/templates/index.html.template.ejs
+++ b/packages/docusaurus/src/webpack/templates/index.html.template.ejs
@@ -2,7 +2,6 @@
-
<%= htmlWebpackPlugin.options.title %>
<%= htmlWebpackPlugin.options.headTags %>
diff --git a/packages/docusaurus/src/webpack/templates/ssr.html.template.ts b/packages/docusaurus/src/webpack/templates/ssr.html.template.ts
index fbbe7fad8a72..ee1f8f1b4716 100644
--- a/packages/docusaurus/src/webpack/templates/ssr.html.template.ts
+++ b/packages/docusaurus/src/webpack/templates/ssr.html.template.ts
@@ -10,15 +10,11 @@ export default `
>
-
- <% if (it.noIndex) { %>
-
- <% } %>
- <%~ it.headTags %>
<% it.metaAttributes.forEach((metaAttribute) => { %>
<%~ metaAttribute %>
<% }); %>
+ <%~ it.headTags %>
<% it.stylesheets.forEach((stylesheet) => { %>
<% }); %>
diff --git a/website/_dogfooding/_pages tests/head-metadata.md b/website/_dogfooding/_pages tests/head-metadata.md
new file mode 100644
index 000000000000..8e16df7033d8
--- /dev/null
+++ b/website/_dogfooding/_pages tests/head-metadata.md
@@ -0,0 +1,17 @@
+## Head Metadata tests
+
+This page declares the following custom head metadata:
+
+```html
+
+
+
+
+
+```
+
+
+
+
+
+
diff --git a/website/_dogfooding/_pages tests/index.md b/website/_dogfooding/_pages tests/index.md
index d54f03fcd3f6..e8bb7fdc7df4 100644
--- a/website/_dogfooding/_pages tests/index.md
+++ b/website/_dogfooding/_pages tests/index.md
@@ -29,3 +29,4 @@ import Readme from "../README.md"
- [TOC tests](/tests/pages/page-toc-tests)
- [Tabs tests](/tests/pages/tabs-tests)
- [z-index tests](/tests/pages/z-index-tests)
+- [Head metadata tests](/tests/pages/head-metadata)
diff --git a/website/docs/api/docusaurus.config.js.md b/website/docs/api/docusaurus.config.js.md
index bc84034ce0bb..254bdc0a2d38 100644
--- a/website/docs/api/docusaurus.config.js.md
+++ b/website/docs/api/docusaurus.config.js.md
@@ -509,15 +509,11 @@ module.exports = {
>
-
- <% if (it.noIndex) { %>
-
- <% } %>
- <%~ it.headTags %>
<% it.metaAttributes.forEach((metaAttribute) => { %>
<%~ metaAttribute %>
<% }); %>
+ <%~ it.headTags %>
<% it.stylesheets.forEach((stylesheet) => { %>
<% }); %>