Skip to content

Commit

Permalink
Dynamic titles
Browse files Browse the repository at this point in the history
  • Loading branch information
raulg committed Mar 15, 2019
1 parent 8185ca7 commit d127e34
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 13 deletions.
13 changes: 3 additions & 10 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
siteMetadata: {
title: `Gatsby Default Starter`,
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
author: `@gatsbyjs`,
title: `Coffee Shop Demo`,
description: `Gatsby + Prismic!`,
author: `@raulg`,
},
plugins: [
`gatsby-plugin-react-helmet`,
Expand All @@ -14,13 +14,6 @@ module.exports = {
previews: true,
}
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
`gatsby-plugin-sass`,
{
resolve: `gatsby-plugin-manifest`,
Expand Down
1 change: 1 addition & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ exports.createPages = createPages(async ({ graphql, actions }) => {
allBlog_homes(uid:null){
edges{
node{
meta_title
_meta{
uid
id
Expand Down
13 changes: 11 additions & 2 deletions src/components/layouts/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import { Link, StaticQuery, graphql } from 'gatsby'
import { linkResolver } from '../../utils/linkResolver'
import { Helmet } from 'react-helmet'

import '../../stylesheets/main.scss'

Expand All @@ -10,13 +11,13 @@ class Layout extends React.Component {
const layoutData = data.prismic.allLayouts.edges[0].node;

const headerItems = layoutData.header_nav_items.map((item) =>
<Link className="header-nav-link" to={linkResolver(item.link._meta)}>
<Link key={item.link._meta.id} className="header-nav-link" to={linkResolver(item.link._meta)}>
{item.text}
</Link>
)

const navItems = layoutData.footer_nav_items.map((item) =>
<Link className="footer-nav-link" to={linkResolver(item.link._meta)}>
<Link key={item.link._meta.id} className="footer-nav-link" to={linkResolver(item.link._meta)}>
{item.text}
</Link>
)
Expand All @@ -35,6 +36,10 @@ class Layout extends React.Component {

return(
<React.Fragment>
<Helmet>
<meta charSet="utf-8" />
<title>{layoutData.site_name}</title>
</Helmet>
<div className="header" id="header">
<div className="header-inner">
<Link className="header-name" to="/">
Expand Down Expand Up @@ -84,12 +89,14 @@ export default props => (
... on PRISMIC_Products{
_meta{
uid
id
type
}
}
... on PRISMIC_Blog_home{
_meta{
uid
id
type
}
}
Expand All @@ -101,12 +108,14 @@ export default props => (
... on PRISMIC_Products{
_meta{
uid
id
type
}
}
... on PRISMIC_Blog_home{
_meta{
uid
id
type
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/slices/FeaturedItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function renderProducts(slice) {
<div key={index} className="products-grid-item-wrapper">
<img className="products-grid-item-image" src={item.link_to_product.product_image.url} alt={item.link_to_product.product_image.alt}/>
<p className="products-grid-item-name">
<Link to={linkResolver(item.link_to_product)}>
<Link to={linkResolver(item.link_to_product._meta)}>
{RichText.asText(item.link_to_product.product_name)}
</Link>
</p>
Expand Down
5 changes: 5 additions & 0 deletions src/templates/blogHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { linkResolver } from '../utils/linkResolver'
import { withPreview } from '@prismicio/gatsby-source-prismic-graphql'
import { Link } from 'gatsby'
import Layout from '../components/layouts'
import { Helmet } from 'react-helmet'

class BlogHome extends React.Component {
constructor(props){
Expand Down Expand Up @@ -56,6 +57,10 @@ class BlogHome extends React.Component {
render() {
return (
<Layout>
<Helmet>
<meta charSet="utf-8" />
<title>{RichText.asText(this.state.doc.meta_title)}</title>
</Helmet>
{this.renderBody()}
</Layout>
);
Expand Down
6 changes: 6 additions & 0 deletions src/templates/blogPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react'
import { RichText } from 'prismic-reactjs'
import { linkResolver } from '../utils/linkResolver'
import { withPreview } from '@prismicio/gatsby-source-prismic-graphql'
import { Helmet } from 'react-helmet'

import Layout from '../components/layouts'

class BlogPost extends React.Component {
Expand Down Expand Up @@ -57,6 +59,10 @@ class BlogPost extends React.Component {
render() {
return(
<Layout>
<Helmet>
<meta charSet="utf-8" />
<title>{RichText.asText(this.state.doc.title)}</title>
</Helmet>
{this.renderBody()}
</Layout>
);
Expand Down
1 change: 1 addition & 0 deletions src/templates/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RichText } from 'prismic-reactjs'
import { linkResolver } from '../utils/linkResolver'
import { CTABanner, FeaturedItems, NumberedItems, Separator, TextBlock } from '../components/slices'
import { withPreview } from '@prismicio/gatsby-source-prismic-graphql'

import Layout from '../components/layouts'

class HomePage extends React.Component {
Expand Down
6 changes: 6 additions & 0 deletions src/templates/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { RichText } from 'prismic-reactjs'
import { linkResolver } from '../utils/linkResolver'
import { Link } from 'gatsby'
import { withPreview } from '@prismicio/gatsby-source-prismic-graphql'
import { Helmet } from 'react-helmet'

import Layout from '../components/layouts'

class Product extends React.Component {
Expand Down Expand Up @@ -102,6 +104,10 @@ class Product extends React.Component {
render() {
return (
<Layout>
<Helmet>
<meta charSet="utf-8" />
<title>{RichText.asText(this.state.doc.product_name)}</title>
</Helmet>
{this.renderBody()}
</Layout>
);
Expand Down
6 changes: 6 additions & 0 deletions src/templates/productsHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { RichText } from 'prismic-reactjs'
import { linkResolver } from '../utils/linkResolver'
import { withPreview } from '@prismicio/gatsby-source-prismic-graphql'
import { Link } from 'gatsby'
import { Helmet } from 'react-helmet'

import Layout from '../components/layouts'

class ProductsHome extends React.Component {
Expand Down Expand Up @@ -57,6 +59,10 @@ class ProductsHome extends React.Component {
render() {
return (
<Layout>
<Helmet>
<meta charSet="utf-8" />
<title>{RichText.asText(this.state.doc.title)}</title>
</Helmet>
{this.renderBody()}
</Layout>
);
Expand Down

0 comments on commit d127e34

Please sign in to comment.