fix(core): allow overriding ssr/dev template meta tags (#7952)

This commit is contained in:
Sébastien Lorber 2022-08-19 16:47:28 +02:00 committed by GitHub
parent c706b23666
commit 94067ce930
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 12 deletions

View file

@ -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 (
<Head>
{/*
charSet + generator are handled in the html templates
See https://github.com/facebook/docusaurus/pull/7952
<meta charSet="UTF-8" />
<meta name="generator" content={`Docusaurus v${docusaurusVersion}`} />
*/}
<html lang={htmlLang} dir={htmlDir} />
<title>{title}</title>
<meta property="og:title" content={title} />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{noIndex && <meta name="robots" content="noindex, nofollow" />}
{favicon && <link rel="icon" href={faviconUrl} />}
</Head>
);

View file

@ -2,7 +2,6 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Docusaurus">
<title><%= htmlWebpackPlugin.options.title %></title>
<%= htmlWebpackPlugin.options.headTags %>

View file

@ -10,15 +10,11 @@ export default `
<html <%~ it.htmlAttributes %>>
<head>
<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, nofollow" />
<% } %>
<%~ it.headTags %>
<% it.metaAttributes.forEach((metaAttribute) => { %>
<%~ metaAttribute %>
<% }); %>
<%~ it.headTags %>
<% it.stylesheets.forEach((stylesheet) => { %>
<link rel="stylesheet" href="<%= it.baseUrl %><%= stylesheet %>" />
<% }); %>

View file

@ -0,0 +1,17 @@
## Head Metadata tests
This page declares the following custom head metadata:
```html
<head>
<meta name="generator" value="custom generator name!" />
<meta name="viewport" content="initial-scale=1, viewport-fit=cover" />
<meta name="robots" content="noindex, nofollow, my-extra-directive" />
</head>
```
<head>
<meta name="generator" value="custom generator name!" />
<meta name="viewport" content="initial-scale=1, viewport-fit=cover" />
<meta name="robots" content="noindex, nofollow, my-extra-directive" />
</head>

View file

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

View file

@ -509,15 +509,11 @@ module.exports = {
<html <%~ it.htmlAttributes %>>
<head>
<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, nofollow" />
<% } %>
<%~ it.headTags %>
<% it.metaAttributes.forEach((metaAttribute) => { %>
<%~ metaAttribute %>
<% }); %>
<%~ it.headTags %>
<% it.stylesheets.forEach((stylesheet) => { %>
<link rel="stylesheet" href="<%= it.baseUrl %><%= stylesheet %>" />
<% }); %>