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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v2): Unbreak blog post title by handling title fallback in LayoutHead #4667

Merged
merged 4 commits into from
Apr 22, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SearchMetadatas from '@theme/SearchMetadatas';
import Seo from '@theme/Seo';
import {
DEFAULT_SEARCH_TAG,
useTitleFormatter,
useAlternatePageUtils,
} from '@docusaurus/theme-common';
import {useLocation} from '@docusaurus/router';
Expand Down Expand Up @@ -90,6 +91,7 @@ export default function LayoutHead(props: Props): JSX.Element {
} = useDocusaurusContext();
const {title, description, image, keywords, searchMetadatas} = props;
const faviconUrl = useBaseUrl(favicon);
const pageTitle = useTitleFormatter(title);

// See https://github.com/facebook/docusaurus/issues/3317#issuecomment-754661855
// const htmlLang = currentLocale.split('-')[0];
Expand All @@ -101,9 +103,11 @@ export default function LayoutHead(props: Props): JSX.Element {
<Head>
<html lang={htmlLang} dir={htmlDir} />
{favicon && <link rel="shortcut icon" href={faviconUrl} />}
<title>{pageTitle}</title>
<meta property="og:title" content={pageTitle} />
</Head>

<Seo {...{title, description, keywords, image}} />
<Seo {...{description, keywords, image}} />

<CanonicalUrlHeaders />

Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-theme-classic/src/theme/Seo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export default function Seo({

return (
<Head>
<title>{pageTitle}</title>
<meta property="og:title" content={pageTitle} />
{title && <title>{pageTitle}</title>}
{title && <meta property="og:title" content={pageTitle} />}

{description && <meta name="description" content={description} />}
{description && <meta property="og:description" content={description} />}
Expand Down