Skip to content

Commit

Permalink
fix(core): allow overriding ssr/dev template meta tags (#7952)
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Aug 19, 2022
1 parent c706b23 commit 94067ce
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
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

0 comments on commit 94067ce

Please sign in to comment.