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

add WP-style page titles #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 12 additions & 3 deletions frontend/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ class Header extends Component {
}

render() {
let title = '';
if ( this.props.title ) {
title = this.props.title;
if ( this.props.settings ) {
title += ' | ' + this.props.settings.site_title;
}
} else if ( this.props.settings ) {
title = this.props.settings.site_title;
} else {
title = 'WordPress + React Starter Kit Frontend by Postlight';
}

return (
<div>
Expand All @@ -21,9 +32,7 @@ class Header extends Component {
content="width=device-width, initial-scale=1"
/>
<meta charSet="utf-8" />
<title>
WordPress + React Starter Kit Frontend by Postlight
</title>
<title>{title}</title>
</Head>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const layoutStyle = {

const Layout = props => (
<div style={layoutStyle}>
<Header />
<Header title={props.title} settings={props.settings} />
{props.children}
<Footer />
</div>
Expand Down
5 changes: 5 additions & 0 deletions frontend/components/PageWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ const PageWrapper = Comp => (
`${Config.apiUrl}/wp-json/menus/v1/menus/header-menu`
);
const headerMenu = await headerMenuRes.json();
const settingsRes = await fetch(
`${Config.apiUrl}/wp-json/postlight/v1/settings`
);
const settings = await settingsRes.json();
return {
headerMenu,
settings,
...(Comp.getInitialProps ? await Comp.getInitialProps(args) : null),
};
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Category extends Component {
);
});
return (
<Layout>
<Layout title={this.props.categories[0].name} settings={this.props.settings}>
<Menu menu={this.props.headerMenu} />
<h1>{this.props.categories[0].name} Posts</h1>
{posts}
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Index extends Component {
);
});
return (
<Layout>
<Layout title={this.props.page.title.rendered} settings={this.props.settings}>
<Menu menu={this.props.headerMenu} />
<img
src="/static/images/wordpress-plus-react-header.png"
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Post extends Component {
if (!this.props.post.title) return <Error statusCode={404} />;

return (
<Layout>
<Layout title={this.props.post.title.rendered} settings={this.props.settings}>
<Menu menu={this.props.headerMenu} />
<h1>{this.props.post.title.rendered}</h1>
<div
Expand Down
Loading