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

feat(gatsby-source-wordpress): Add "path" field to post/page/custom post type entities #11775

Merged

Conversation

riddla
Copy link
Contributor

@riddla riddla commented Feb 14, 2019

Description

Picked up from the documentation change over at #11126, this makes a path field available within the WordPress entities.

Usage example

// [...]
graphql(
  `
    {
      allWordpressPage {
        edges {
          node {
            id
            link
            path
            status
            template
          }
        }
      }
    }
  `
).then(result => {
  if (result.errors) {
    console.log(result.errors)
    reject(result.errors)
  }

  const pageTemplate = path.resolve(`./src/templates/page.js`)

  _.each(result.data.allWordpressPage.edges, edge => {
    createPage({
      path: edge.node.path,
      component: slash(pageTemplate),
      context: {
        id: edge.node.id,
      },
    })
  })
});
// [...]

Related Issues

Related to #11126

@riddla riddla requested a review from pieh February 14, 2019 18:30

exports.createUrlPathsFromLinks = entities =>
entities.map(e => {
if (e.__type === `wordpress__PAGE` || e.__type === `wordpress__POST`) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't handle custom post types. I wonder if we instead could check:

if (e.link && !e.path) 

to check if link is on entity and just sanity check to not override path field if it already exists (someone or some plugin enriching REST endpoint on wordpress side)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your feedback. Also the sanity check makes totally sense.

I was conservative regarding the types, as the current Wordpress project I use for testing only has normal pages and posts.
But I should have a deeper look into the example data stemming from the official Gatsby demo wordpress site.

I’ll try it tomorrow :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pieh, I added your suggestion.

@ghost
Copy link

ghost commented Feb 18, 2019

Thanks for this PR @riddla! Looks good, I will update #11126 when this gets merged.

@sidharthachatterjee
Copy link
Contributor

@riddla Could you please fix the linting issue? Looks great otherwise!

@riddla
Copy link
Contributor Author

riddla commented Feb 21, 2019

@sidharthachatterjee, we should be good now regarding ESLint.

@riddla
Copy link
Contributor Author

riddla commented Feb 25, 2019

@pieh, @sidharthachatterjee, we should be good here?

@sidharthachatterjee sidharthachatterjee force-pushed the feat/add-paths-to-gatsby-source-wordpress branch from b082cdb to 2cd77fc Compare February 26, 2019 01:50
@pieh pieh self-assigned this Feb 26, 2019
@pieh
Copy link
Contributor

pieh commented Feb 26, 2019

Awesome!
screenshot 2019-02-26 at 14 10 32

creating paths that matches Wordpress URLs will be much easier now!

@pieh pieh changed the title feat(gatsby-source-wordpress): Add "path" field to post/page entities feat(gatsby-source-wordpress): Add "path" field to post/page/custom post type entities Feb 26, 2019
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

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

Thanks @riddla! 🎉

@pieh pieh merged commit 0b39498 into gatsbyjs:master Feb 26, 2019
@riddla riddla deleted the feat/add-paths-to-gatsby-source-wordpress branch February 27, 2019 11:29
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.

None yet

3 participants