Skip to content

Commit 697592d

Browse files
authored
docs: update title and meta information on page change (#474)
1 parent 831e5bb commit 697592d

File tree

8 files changed

+199
-102
lines changed

8 files changed

+199
-102
lines changed

package-lock.json

Lines changed: 167 additions & 96 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"react-dev-utils": "^6.1.1",
121121
"react-dom": "^16.6.3",
122122
"react-element-to-jsx-string": "^14.0.2",
123+
"react-helmet-async": "^0.2.0",
123124
"react-markdown": "^4.0.6",
124125
"react-router": "^4.3.1",
125126
"react-router-dom": "^4.3.1",

src/_playground/App.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import './App.scss';
22
import '@babel/polyfill';
3+
import { HelmetProvider } from 'react-helmet-async';
34
import { Routes } from './Routes';
45
import React, { Component } from 'react';
56

67
class App extends Component {
78
render() {
89
return (
9-
<div className='frDocs-App'>
10-
<Routes />
11-
</div>
10+
<HelmetProvider>
11+
<div className='frDocs-App'>
12+
<Routes />
13+
</div>
14+
</HelmetProvider>
1215
);
1316
}
1417
}

src/_playground/Routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export class Routes extends Component {
364364
<a
365365
aria-label='Home'
366366
className='frDocs-Menu__logo'
367-
href='/'>
367+
href='/home'>
368368
Fundamental <span className='frDocs-Menu__logo--library'>React</span>
369369
</a>
370370
<span className='frDocs-Menu__spacer' />

src/_playground/documentation/Template/ComponentPage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
33
import tocbot from 'tocbot';
4-
import { Contents, Description, Header, Heading, Import, Properties, Separator } from '..';
4+
import { Contents, Description, Header, Heading, Import, Properties, Separator, SetMeta } from '..';
55

66
class ComponentPage extends React.Component {
77
componentDidMount() {
@@ -26,6 +26,7 @@ class ComponentPage extends React.Component {
2626

2727
return (
2828
<React.Fragment>
29+
<SetMeta title={title} />
2930
<Header>{title}</Header>
3031
<Description>{description}</Description>
3132
<Import sourceModulePath={sourceModulePath} />

src/_playground/documentation/Template/MarkdownPage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import MarkdownImporter from '../Markdown/MarkdownImporter';
22
import PropTypes from 'prop-types';
33
import React from 'react';
44
import tocbot from 'tocbot';
5-
import { Contents, Description, Header, Heading, Separator } from '../';
5+
import { Contents, Description, Header, Heading, Separator, SetMeta } from '../';
66

77
class MarkdownPage extends React.Component {
88
componentDidMount() {
@@ -31,6 +31,7 @@ class MarkdownPage extends React.Component {
3131
// we will pass our own heading renderer so we can inject id values for the TOC
3232
return (
3333
<React.Fragment>
34+
<SetMeta title={title} />
3435
{title && <Header>{title}</Header>}
3536
{description && <Description>{description}</Description>}
3637
<Contents />

src/_playground/documentation/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export { default as Properties } from './Properties/Properties';
1111
export { default as Separator } from './Separator/Separator';
1212
export { default as DocsText } from './DocsText/DocsText';
1313
export { default as DocsTile } from './DocsTile/DocsTile';
14+
export { default as SetMeta } from './utils/SetMeta';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Helmet from 'react-helmet-async';
2+
import PropTypes from 'prop-types';
3+
import React from 'react';
4+
5+
const SetMeta = ({ title }) => {
6+
return (
7+
<Helmet
8+
defaultTitle='Fundamental React'
9+
titleTemplate='Fundamental React - %s'>
10+
<title>{title}</title> />
11+
</Helmet>
12+
);
13+
};
14+
15+
SetMeta.propTypes = {
16+
title: PropTypes.string.isRequired
17+
};
18+
19+
export default SetMeta;

0 commit comments

Comments
 (0)