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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/docusaurus/src/client/SiteMetadataDefaults.tsx
Expand Up @@ -12,17 +12,25 @@ 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);
const {htmlLang, direction: htmlDir} = localeConfigs[currentLocale]!;

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>
);
Expand Down
Expand Up @@ -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 %>
Expand Down
Expand Up @@ -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 %>" />
<% }); %>
Expand Down
17 changes: 17 additions & 0 deletions website/_dogfooding/_pages tests/head-metadata.md
@@ -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>
1 change: 1 addition & 0 deletions website/_dogfooding/_pages tests/index.md
Expand Up @@ -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)
6 changes: 1 addition & 5 deletions website/docs/api/docusaurus.config.js.md
Expand Up @@ -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 %>" />
<% }); %>
Expand Down