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

Wordpress source plugin and example site #1321

Merged
merged 16 commits into from
Jul 6, 2017
Merged

Wordpress source plugin and example site #1321

merged 16 commits into from
Jul 6, 2017

Conversation

sebastienfi
Copy link
Contributor

This is a first PR for a gatsby-source-plugin and using-wordpress example.

The source plugin is published on NPM --> https://www.npmjs.com/package/gatsby-source-wordpress

The example site uses :

  • Styled-components
  • Wordpress.com as a source using gatsby-source-wordpress
  • Hedron as a gridsystem

I tried to make the site the ugliest on the internet as a praise to 1980's internet. I hope I succeeded.

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Jul 1, 2017

Deploy preview failed.

Built with commit 4ac59b9

https://app.netlify.com/sites/using-contentful/deploys/59592934a700c46a8e33aa50

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 1, 2017

Deploy preview ready!

Built with commit 4ac59b9

https://deploy-preview-1321--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 1, 2017

Deploy preview ready!

Built with commit 4ac59b9

https://deploy-preview-1321--gatsbyjs.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jul 1, 2017

Deploy preview ready!

Built with commit 4ac59b9

https://deploy-preview-1321--gatsbygram.netlify.com

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! Really excited to get this in.

It'd be great to get some testing going for this. I've been playing a lot with design/testing strategies for source plugins so let's chat later.

You should run from the base of the repo npm run format to fix up code with Prettier. I noticed your clone of the git repo is a bit out of date so you'll probably want to update to the latest 1.0 code so you're formatting your code with the latest Prettier.

@@ -0,0 +1,27 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kill this file — the gatsby repo has its own .eslintrc file that everything should follow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -0,0 +1,47 @@
# Logs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably isn't necessary either

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -0,0 +1,39 @@
# back to language cpp to try to bypass osx node failure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -0,0 +1 @@
siteTitle="Sample site"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.toml is just for Gatsby v0. We don't use it any more in Gatsby v1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

"gatsby-source-filesystem": "next",
"gatsby-transformer-sharp": "next",
"gatsby-source-wordpress": "next",
"graphql": "^0.10.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is supplied by gatsby

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

"gatsby-source-wordpress": "next",
"graphql": "^0.10.3",
"hedron": "^0.7.1",
"highlight": "^0.2.4",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you're not using this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

"json-stringify-safe": "^5.0.1",
"lodash": "^4.16.4",
"qs": "^6.4.0",
"react-helmet": "^5.1.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

install gatsby-plugin-react-helmet instead — that then handles the server rendering for you. Do the same with react-plugin-styled-components

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.
#1341

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{this.props.headComponents}
{css}
{head.title.toComponent()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove these after gatsby-plugin-react-helmet is installed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -0,0 +1,700 @@
'use strict';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be committed — related to the needed changes in .gitignore/.npmignore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

let siteURL


// ======== Main Void ==========
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's "Main Void" mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means it's the entry point.

@0x80
Copy link
Contributor

0x80 commented Jul 2, 2017

@sebastienfi looks like the plugin source is not publicly available?

@sebastienfi
Copy link
Contributor Author

@0x80 : I don't know how to check if the code is public... The forked repo is public. What happens when you try to see the latest commit ? 4ac59b9

@0x80
Copy link
Contributor

0x80 commented Jul 2, 2017

@sebastienfi Since you published it on npm from your username, I assumed that you would have this code in an isolated public repo. I see now that you forked Gatsby and coded the plugin as a package.

If I understand this correctly I think you shouldn't have published the source plugin on npm yourself, because it will be part of the Gatsby repo and all packages should be published from there. Lerna manages the packages for Gatsby because it is a monorepo.

}
`
)
.then(result => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could destructure (in many places)

.then(({ errors, data }) => {

${props => PR.colorProps(props)}
${PR.marginProps}
`;
export const H7 = styled.h6`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no H7. was this deliberate?

/* Global Tags */
export const H1 = styled.h1`
${props => PR.ftzProps(props, ftz.h1)}
${props => PR.colorProps(props)}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For your consideration...

This could be DRYed up a lot. for example, something like this (untested) maybe?

const styleHeader level => {
  const hx = `h${level}`;
  return styled[hx]`
    ${props => PR.ftzProps(props, ftz[hx])}
    ${props => PR.colorProps(props)}
    ${PR.marginProps}
  `;
};

then

const [H1, H2, H3, H4, H5, H6]  = [1, 2, 3, 4, 5, 6].map(styleHeader);

}

DefaultLayout.propTypes = {
location: PropTypes.object.isRequired,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You specify location as required, but then you never use it.

import React from 'react';
import PropTypes from 'prop-types';

class DefaultLayout extends React.Component {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SFC?

const DefaultLayout = ({ children }) => (
  <div>{children}</div>
);

Also can you get away without the div wrapper by returning React.Children.only(children)?

font-weight: ${fontWeight};
}
`
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that you can avoid string concatenation by doing this:

export function fontFaceHelper(name, src, fontWeight = 'normal', fontStyle = 'normal') {
  cont woff = `../assets/fonts/${src}.woff`;
  cont woff2 = `../assets/fonts/${src}.woff2`;
  return `
    @font-face{
      font-family: "${name}";
      src: url(${require(woff)}) format("woff"),
           url(${require(woff2)}#${name}) format("woff2");
      font-style: ${fontStyle};
      font-weight: ${fontWeight};
    }
  `;
}

@@ -0,0 +1,47 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, chalk is a very popular way of adding color in node that you could use instead of your own module https://www.npmjs.com/package/chalk

@KyleAMathews
Copy link
Contributor

hey! Let's get this in. Really looking forward to the army of Wordpress/Gatsby clones that'll be emerging soon :-D

@KyleAMathews KyleAMathews merged commit 0f8c626 into gatsbyjs:1.0 Jul 6, 2017
@whmountains
Copy link

Wow, that came just in time. I have a client that lined up that already has a Wordpress website, so I'll probably be using this.

@cr101
Copy link

cr101 commented Jul 15, 2017

@sebastienfi is there any chance the example in using-wordpress could be expanded to fetch WordPress posts and authors based on a keyword search. For example, as you type display all posts and authors that match the search term "keyword".

@corysimmons
Copy link
Contributor

Can we get some more docs on WordPress/Gatsby usage?

I have a fresh install of WP on a remote server, and a fresh install of Gatsby locally. I installed the npm pkgs (Bluebird, etc.) and copypasted gatsby-node.js from this PR to ./gatsby-node.js in my Gatsby project.

I get GraphQLError: Cannot query field "allWordpressPage" on type "RootQueryType". Did you mean "allSitePage"?

A really barebones example with a fresh WP install on localhost or a remote server would do wonders for my self-esteem.

@sebastienfi
Copy link
Contributor Author

@cr101 yes you can do that.
PS : Sorry I bumped into your message so late!

@cr101
Copy link

cr101 commented Aug 16, 2017

@sebastienfi Any idea if Advanced Custom Fields (ACF) is entirely WP REST API ready? If so, does ACF expose the endpoints for custom post types, taxonomies and custom fields in the REST API? Is there a plugin required to expose the endpoints?
Have you used ACF? If so, does it work well with Gatsby?

I've been evaluating PODS which is an awesome awesome plugin but unfortunately PODS doesn't currently have repeating groups fields which is a shame because it's entirely REST API ready.
Toolset Types is not REST API ready at all so I'm hoping that ACF is REST API ready.

@sebastienfi
Copy link
Contributor Author

sebastienfi commented Aug 16, 2017

@cr101 I'm using ACF Pro mainly so the plugin is compatible with it on all aspects. Read the doc of the source plugin and search for ACF you'll find plenty of intel.

https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-wordpress

ACF will work with the other plugin mentioned in the docs that exposes ACF field to endpoints. It will work with custom post types and stuff.

@cr101
Copy link

cr101 commented Aug 16, 2017

@sebastienfi Is ACF PRO entirely REST API ready or do I need a plugin to expose the endpoints?
UPDATE:
oh, I found it - acf-to-rest-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants