Skip to content

Commit

Permalink
Remove react-helmet from src/html.js fixes #1443 (#1474)
Browse files Browse the repository at this point in the history
* Remove react-helmet from src/html.js as that's handled by gatsby-plugin-react-helmet

* Run format
  • Loading branch information
KyleAMathews authored Jul 11, 2017
1 parent bfb4f8d commit 5a37ebd
Show file tree
Hide file tree
Showing 25 changed files with 1,024 additions and 786 deletions.
73 changes: 36 additions & 37 deletions examples/using-wordpress/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ const _ = require(`lodash`)
const Promise = require(`bluebird`)
const path = require(`path`)
const slash = require(`slash`)
// Implement the Gatsby API “createPages”. This is
// called after the Gatsby bootstrap is finished so you have
// access to any information necessary to programatically
// create pages.
// Will create pages for Wordpress pages (route : /{slug})
// Will create pages for Wordpress posts (route : /post/{slug})

// Implement the Gatsby API “createPages”. This is
// called after the Gatsby bootstrap is finished so you have
// access to any information necessary to programatically
// create pages.
// Will create pages for Wordpress pages (route : /{slug})
// Will create pages for Wordpress posts (route : /post/{slug})
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators
return new Promise((resolve, reject) => {
// The “graphql” function allows us to run arbitrary
// queries against the local Wordpress graphql schema. Think of
// it like the site has a built-in database constructed
// from the fetched data that you can run queries against.
// ==== PAGES (WORDPRESS NATIVE) ====
// The “graphql” function allows us to run arbitrary
// queries against the local Wordpress graphql schema. Think of
// it like the site has a built-in database constructed
// from the fetched data that you can run queries against.

// ==== PAGES (WORDPRESS NATIVE) ====
graphql(
`
{
Expand All @@ -41,21 +41,21 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
console.log(result.errors)
reject(result.errors)
}
// Create Page pages.
const pageTemplate = path.resolve('./src/templates/page.js')
// We want to create a detailed page for each
// page node. We'll just use the Wordpress Slug for the slug.
// The Page ID is prefixed with 'PAGE_'

// Create Page pages.
const pageTemplate = path.resolve(`./src/templates/page.js`)
// We want to create a detailed page for each
// page node. We'll just use the Wordpress Slug for the slug.
// The Page ID is prefixed with 'PAGE_'
_.each(result.data.allWordpressPage.edges, edge => {
// Gatsby uses Redux to manage its internal state.
// Plugins and sites can use functions like "createPage"
// to interact with Gatsby.
// Gatsby uses Redux to manage its internal state.
// Plugins and sites can use functions like "createPage"
// to interact with Gatsby.
createPage({
// Each page is required to have a `path` as well
// as a template component. The `context` is
// optional but is often necessary so the template
// can query data specific to each page.
// Each page is required to have a `path` as well
// as a template component. The `context` is
// optional but is often necessary so the template
// can query data specific to each page.
path: `/${edge.node.slug}/`,
component: slash(pageTemplate),
context: {
Expand All @@ -64,9 +64,9 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
})
})
})
// ==== END PAGES ====
// ==== POSTS (WORDPRESS NATIVE AND ACF) ====
// ==== END PAGES ====

// ==== POSTS (WORDPRESS NATIVE AND ACF) ====
.then(() => {
graphql(
`{
Expand All @@ -89,10 +89,10 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
console.log(result.errors)
reject(result.errors)
}
const postTemplate = path.resolve('./src/templates/post.js')
// We want to create a detailed page for each
// post node. We'll just use the Wordpress Slug for the slug.
// The Post ID is prefixed with 'POST_'
const postTemplate = path.resolve(`./src/templates/post.js`)
// We want to create a detailed page for each
// post node. We'll just use the Wordpress Slug for the slug.
// The Post ID is prefixed with 'POST_'
_.each(result.data.allWordpressPost.edges, edge => {
createPage({
path: `/post/${edge.node.slug}/`,
Expand All @@ -104,8 +104,7 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
})
resolve()
})
})
// ==== END POSTS ====

})
// ==== END POSTS ====
})
}
}
10 changes: 4 additions & 6 deletions examples/using-wordpress/src/components/Footer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React from 'react';
import { Page, Row } from './styled';
import React from "react"
import { Page, Row } from "./styled"

const Footer = props =>
<footer>
<Page>
<Row height={5}>
This is a sample footer.
</Row>
<Row height={5}>This is a sample footer.</Row>
</Page>
</footer>

export default Footer;
export default Footer
44 changes: 27 additions & 17 deletions examples/using-wordpress/src/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
import React from 'react';
import PropTypes from 'prop-types';
import Link from 'gatsby-link';
import { H1, H2, H3, H4 } from '../components/styled';
import { Row, Page, Column } from './styled';

const Header = ({ title, subtitle, pages }) => {
import React from "react"
import PropTypes from "prop-types"
import Link from "gatsby-link"
import { H1, H2, H3, H4 } from "../components/styled"
import { Row, Page, Column } from "./styled"

const Header = ({ title, subtitle, pages }) =>
// TODO : Sort order of menu based on field menu_order
return (
(
<Page>
<Row>
<H3>{title}</H3>
<H3>
{title}
</H3>
</Row>
<Row>
<H4>{subtitle}</H4>
<H4>
{subtitle}
</H4>
</Row>
<Row>
<Column fluid xs={1} sm={10} md={10} lg={10}>
<span><Link to={'/'}>Home</Link> - </span>
<span>
<Link to={`/`}>Home</Link> -{` `}
</span>
{pages.edges.map((p, i) => {
if (p.node.slug == 'blog') return
if (p.node.slug == 'home') return
return <span key={p.node.id}>{i !== 0 ? ' - ' : ''}<Link to={p.node.slug}>{unescape(p.node.title)}</Link></span>
if (p.node.slug == `blog`) return
if (p.node.slug == `home`) return
return (
<span key={p.node.id}>
{i !== 0 ? ` - ` : ``}
<Link to={p.node.slug}>
{unescape(p.node.title)}
</Link>
</span>
)
})}
</Column>
<hr />
</Row>
</Page>
)
}

Header.propTypes = {
title: PropTypes.string,
pages: PropTypes.object.isRequired,
}


export default Header;
export default Header
41 changes: 27 additions & 14 deletions examples/using-wordpress/src/components/PostPreview.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Row, Page, Column, BlockLink, P2, P4 } from './styled';
import styled from 'styled-components';
import theme from './styled/theme';
import React from "react"
import PropTypes from "prop-types"
import { Row, Page, Column, BlockLink, P2, P4 } from "./styled"
import styled from "styled-components"
import theme from "./styled/theme"

const BlogPreviewImg = styled.img`
width: 100%;
`;
const BlogPreviewImg = styled.img`width: 100%;`

const PostPreview = ({ article, id }) => {
console.log('article is', article)
console.log(`article is`, article)
return (
<Column outline fluid xs={4} sm={4} md={4} lg={4}>
<BlockLink to={`/post/${id}`} paddingHorizontal={2} paddingTop={2} paddingBottom={5} block>
<BlogPreviewImg src={'http://via.placeholder.com/416x245'} alt="placeholder"/>
<P2 color={theme.color.han} dangerouslySetInnerHTML={{ __html: article.node.title }}></P2>
<P4 color={theme.color.han} dangerouslySetInnerHTML={{ __html: article.node.excerpt }}></P4>
<BlockLink
to={`/post/${id}`}
paddingHorizontal={2}
paddingTop={2}
paddingBottom={5}
block
>
<BlogPreviewImg
src={`http://via.placeholder.com/416x245`}
alt="placeholder"
/>
<P2
color={theme.color.han}
dangerouslySetInnerHTML={{ __html: article.node.title }}
/>
<P4
color={theme.color.han}
dangerouslySetInnerHTML={{ __html: article.node.excerpt }}
/>
<P4 color={theme.color.link}>Read More</P4>
</BlockLink>
</Column>
Expand All @@ -27,4 +40,4 @@ PostPreview.propType = {
id: PropTypes.string,
}

export default PostPreview;
export default PostPreview
59 changes: 27 additions & 32 deletions examples/using-wordpress/src/components/PostsListSearchable.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,63 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { H3, Row, Page, Column } from './styled';
import PostPreview from './PostPreview'
import React, { Component } from "react"
import PropTypes from "prop-types"
import { H3, Row, Page, Column } from "./styled"
import PostPreview from "./PostPreview"

class PostsListSearchable extends Component {

// Put the props in the state
constructor(props) {
super(props)
this.state = {
data: this.props.propsData.allWordpressPost.edges
data: this.props.propsData.allWordpressPost.edges,
}
}

handleFilter = id => {
this.setState({
data: this.props.propsData.allWordpressPost.edges.filter(p => {
return p.node.categories.includes(id.replace('CATEGORY_', ''))
})
data: this.props.propsData.allWordpressPost.edges.filter(p => p.node.categories.includes(id.replace(`CATEGORY_`, ``))),
})
}

resetFilter = () => this.setState({ data: this.props.propsData.allWordpressPost.edges })
resetFilter = () =>
this.setState({ data: this.props.propsData.allWordpressPost.edges })

render() {

return (
<Page>
<H3>The latests blog posts</H3>
<Row gutter gutterWhite>
<Column fluid xs={1} sm={10} md={10} lg={10}>
<span>Filter by category: </span>
<span>Filter by category: </span>
<span onClick={() => this.resetFilter()}>All - </span>
{
this.props.propsData.allWordpressCategory.edges.map((cat, i) => {

return (<span
key={cat.node.id}
onClick={() => this.handleFilter(cat.node.id)}
>
{i !== 0 ? ' - ':''}{cat.node.name}
</span>)
})
}
{this.props.propsData.allWordpressCategory.edges.map((cat, i) => (
<span
key={cat.node.id}
onClick={() => this.handleFilter(cat.node.id)}
>
{i !== 0 ? ` - ` : ``}
{cat.node.name}
</span>
))}
<span onClick={() => this.resetFilter()}> - Reset filter</span>
</Column>
</Row>
<Row gutter>
{
this.state.data.map(article =>
<PostPreview key={article.node.slug} id={article.node.slug} article={article} />)}
</Row>
<Row gutter height={19}>
{this.state.data.map(article =>
<PostPreview
key={article.node.slug}
id={article.node.slug}
article={article}
/>
)}
</Row>
<Row gutter height={19} />
</Page>
)
}


}


PostsListSearchable.propTypes = {
propsData: PropTypes.object.isRequired,
}

export default PostsListSearchable;
export default PostsListSearchable
Loading

0 comments on commit 5a37ebd

Please sign in to comment.