Basic config and layout for fetching, showing wp data with graphql
This commit is contained in:
@@ -17,6 +17,20 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
)
|
).then(result => {
|
||||||
|
if (result.errors) {
|
||||||
|
console.log(result.errors)
|
||||||
|
reject(result.errors)
|
||||||
|
}
|
||||||
|
|
||||||
|
result.data.allWordpressPage.edges.forEach(({ node }) => {
|
||||||
|
createPage({
|
||||||
|
path: node.slug,
|
||||||
|
component: path.resolve('./src/pages/page.js'),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/components/header.js
Normal file
18
src/components/header.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import Link from 'gatsby-link'
|
||||||
|
|
||||||
|
const Header = ({ siteTitle }) => (
|
||||||
|
<h1 style={{ margin: 0 }}>
|
||||||
|
<Link
|
||||||
|
to="/"
|
||||||
|
style={{
|
||||||
|
color: 'white',
|
||||||
|
textDecoration: 'none',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{siteTitle}
|
||||||
|
</Link>
|
||||||
|
</h1>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default Header
|
||||||
35
src/layouts/index.js
Normal file
35
src/layouts/index.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import Helmet from 'react-helmet'
|
||||||
|
|
||||||
|
import Header from '../components/header'
|
||||||
|
|
||||||
|
const Layout = ({ children, data }) => (
|
||||||
|
<div>
|
||||||
|
<Helmet
|
||||||
|
title={data.site.siteMetadata.title}
|
||||||
|
meta={[
|
||||||
|
{ name: 'description', content: 'We code & design great software' },
|
||||||
|
{ name: 'keywords', content: 'software, design, coding, programming, code, consulting' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<Header siteTitle={data.site.siteMetadata.title} />
|
||||||
|
{children()}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
Layout.propTypes = {
|
||||||
|
children: PropTypes.func,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Layout
|
||||||
|
|
||||||
|
export const query = graphql`
|
||||||
|
query SiteTitleQuery {
|
||||||
|
site {
|
||||||
|
siteMetadata {
|
||||||
|
title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
10
src/pages/404.js
Normal file
10
src/pages/404.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
const NotFoundPage = () => (
|
||||||
|
<div>
|
||||||
|
<h1>NOT FOUND</h1>
|
||||||
|
<p>You just hit a route that doesn't exist... the sadness.</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default NotFoundPage
|
||||||
9
src/pages/index.js
Normal file
9
src/pages/index.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
const IndexPage = () => (
|
||||||
|
<div>
|
||||||
|
<h1>Index page</h1>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default IndexPage
|
||||||
24
src/pages/page.js
Normal file
24
src/pages/page.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
|
class Page extends Component {
|
||||||
|
render() {
|
||||||
|
const { data } = this.props
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Specific Page - {data.wordpressPage.title}</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const query = graphql`
|
||||||
|
query PageQuery {
|
||||||
|
wordpressPage(slug: {eq: "about"}) {
|
||||||
|
title
|
||||||
|
slug
|
||||||
|
content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
export default Page;
|
||||||
Reference in New Issue
Block a user