-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Wordpress source plugin and example site #1321
Conversation
Deploy preview failed. Built with commit 4ac59b9 https://app.netlify.com/sites/using-contentful/deploys/59592934a700c46a8e33aa50 |
Deploy preview ready! Built with commit 4ac59b9 |
Deploy preview ready! Built with commit 4ac59b9 |
Deploy preview ready! Built with commit 4ac59b9 |
There was a problem hiding this 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.
examples/using-wordpress/.eslintrc
Outdated
@@ -0,0 +1,27 @@ | |||
{ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
examples/using-wordpress/.gitignore
Outdated
@@ -0,0 +1,47 @@ | |||
# Logs |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
examples/using-wordpress/.travis.yml
Outdated
@@ -0,0 +1,39 @@ | |||
# back to language cpp to try to bypass osx node failure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
examples/using-wordpress/config.toml
Outdated
@@ -0,0 +1 @@ | |||
siteTitle="Sample site" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
#1341
examples/using-wordpress/src/html.js
Outdated
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
{this.props.headComponents} | ||
{css} | ||
{head.title.toComponent()} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ========== |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…astienfi/gatsby into topics/wordpress-source-site
…ything should follow
@sebastienfi looks like the plugin source is not publicly available? |
@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 => { |
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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)} |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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}; | ||
} | ||
` | ||
} |
There was a problem hiding this comment.
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 @@ | |||
/** |
There was a problem hiding this comment.
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
hey! Let's get this in. Really looking forward to the army of Wordpress/Gatsby clones that'll be emerging soon :-D |
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. |
@sebastienfi is there any chance the example in |
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 I get A really barebones example with a fresh WP install on localhost or a remote server would do wonders for my self-esteem. |
@cr101 yes you can do that. |
@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? 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. |
@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. |
@sebastienfi Is ACF PRO entirely REST API ready or do I need a plugin to expose the endpoints? |
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 :
I tried to make the site the ugliest on the internet as a praise to 1980's internet. I hope I succeeded.