Skip to content

Commit

Permalink
feat(v2): add site title to meta title (#2255)
Browse files Browse the repository at this point in the history
* feat(v2): add site title to meta title

* Change page separator

* Exlucde tagline from empty title

* Use tagline for title on home page
  • Loading branch information
lex111 authored Jan 31, 2020
1 parent 2cc4111 commit d1219b1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/docusaurus-theme-classic/src/theme/DocItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Headings({headings, isChild}) {

function DocItem(props) {
const {siteConfig = {}} = useDocusaurusContext();
const {url: siteUrl} = siteConfig;
const {url: siteUrl, title: siteTitle} = siteConfig;
const {content: DocContent} = props;
const {metadata} = DocContent;
const {
Expand All @@ -79,7 +79,11 @@ function DocItem(props) {
return (
<>
<Head>
{title && <title>{title}</title>}
{title && (
<title>
{title} | {siteTitle}
</title>
)}
{description && <meta name="description" content={description} />}
{description && (
<meta property="og:description" content={description} />
Expand Down
5 changes: 2 additions & 3 deletions packages/docusaurus-theme-classic/src/theme/Layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ function Layout(props) {
const {siteConfig = {}} = useDocusaurusContext();
const {
favicon,
tagline,
title: defaultTitle,
title: siteTitle,
themeConfig: {image: defaultImage},
url: siteUrl,
} = siteConfig;
Expand All @@ -35,7 +34,7 @@ function Layout(props) {
permalink,
version,
} = props;
const metaTitle = title || `${defaultTitle} · ${tagline}`;
const metaTitle = title ? `${title} | ${siteTitle}` : siteTitle;
const metaImage = image || defaultImage;
const metaImageUrl = siteUrl + useBaseUrl(metaImage);
const faviconUrl = useBaseUrl(favicon);
Expand Down
7 changes: 5 additions & 2 deletions website/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ const QUOTES = [

function Home() {
const context = useDocusaurusContext();
const {siteConfig: {customFields = {}} = {}} = context;
const {siteConfig: {customFields = {}, tagline} = {}} = context;

return (
<Layout permalink="/" description={customFields.description}>
<Layout
permalink="/"
title={tagline}
description={customFields.description}>
<div className={styles.hero}>
<div className={styles.heroInner}>
<h1 className={styles.heroProjectTagline}>
Expand Down

0 comments on commit d1219b1

Please sign in to comment.