-
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
[gatsby-source-wordpress] Implementing gatsby-image for WYSIWYG fields #7567
Conversation
Very interesting feature @lightstrike , I have been willing to do that from day one of the plugin. I am fully booked on a project until the end of this year, but I am planning to come back to GatsbyJS as soon as January 2nd 2019 10am. Therefore, I won't provide you with the review you requested but I am definitely looking forward to see this feature happily merged ;-) |
Very cool
From the MDX perspective this isn't needed because we already provide hooks to apply mdast/hast/rehype/etc plugins both directly, and soon wrapped in gatsby logic as well (that is, support for the gatsby-remark-* style plugin ecosystem). I should test out wordpress as a source plugin sometime. Maybe it would be good to include a way to say "this MDX content is coming in as html, convert it to mdast please" and then when using the gatsby-mdx transformer option (like we do for contentful) all the mdPlugins spec'd in gatsby-mdx's options would run. transformers: {
ContentfulBlogPost: ({ node, getNode }) => {
const { title } = node
const mdxContent = getNode(node.mdxContent___NODE)
return { meta: { title }, content: mdxContent.mdxContent }
},
}, |
Potentially tag like |
fc4ca3e
to
2116fff
Compare
Hey @lightstrike! Thanks for doing this work and sorry to be so late to the party. I'm a bit hesitant of putting this in the WordPress plugin as this adds some complexity to it. I love the idea and it would be great for our WordPress users! We have a wordpress RFC running where this functionality falls right into. It would be great if you could chime in the discussion :D |
I'll close this PR as we have much better implementation options (as in not cramming this functionality in wordpress plugin). With schema customization that landed recently, we can create generic html transformer and declare that some field have html as content, so transformer would take care of them - here's proof of concept of this approach that does similar thing - https://github.com/pieh/html-transformer-wp |
@pieh This looks super promising! Is gastby-transformer-html published as its own plugin? I have a few thoughts on implementation I'll share in that repo. Also where's the best place to review how schema customization works? Great stuff 🙌 |
It's not published, but I might do it today with 0.0.1 versions (so at very least we have dibs on |
As for schema customization - we don't have guides yet - so available resources are API reference:
And couple of blog posts: We also continuously work on it (i.e. #13028 ), as right now we have basic APIs that allow to adjust schema, but we don't yet have convenience functions or access to some utilities from Gatsby core that will make working with schema much nicer. |
Is there any potential to apply this approach toward gatsby-source-graphql? I've been experimenting with WPGraphQL and it's fun to see @jasonbahl is getting into Gatsby. Ultimately I think making transformations on stitched GraphQL APIs that would be the best long-term approach with WordPress and Gatsby. |
I’m always open to doing what I can on the WPGrapHQL side to make it easier to work with Gatsby. If there’s anything I can contribute on this end, I’m open for ideas. 😀 |
That's the goal. We were using mostly It should be possible right now (using |
The core feature this PR aims to add is the ability to replace
<img>
elements in WordPress post and page WYSIWYG fields with Gatsby<Img>
components. This feature has been requested in different contexts, such as #1493, #3733 and #6799.What I really want is to map elements to React components, exactly along the lines of what is in the pipeline for gatsby-mdx and in the
using-remark
custom components example. I believe enabling this will really open the floodgates for creativity in migrating from legacy CMS frameworks to Gatsby. This gets especially interesting with WordPress Gutenberg blocks, as #7465 recently brought up.To enable the core feature, these steps were taken:
content
fields of WordPress Posts and Pages usingparse5
selectAll
fromhast-util-select
getNodes
createRemoteFileNode
fluid
function fromgatsby-plugin-sharp
gatsby-remark-images
astToHtml
fromhast-util-to-html
I'm leveraging
onCreateNode
here with ahastOptions
option added to the plugin ingatsby-config.js
, creating the possibility to do any kind of transformations on any HTML field:While I believe (and hope!) many others will find this kind of functionality useful for
gatsby-source-wordpress
, I don't believe this PR should be merged as-is or even with minor modifications. It adds too much complexity and too many dependencies to the core WordPress plugin. I see the intersection of three big opportunities here:gatsby-transformer-hast
ecosystem to complementgatsby-transformer-remark
(alluded to here)gatsby-source-wordpress
plugin, as explored in Create RFC for extending Gatsby's WordPress plugin #5796gatsby-source-wordpress
data pipeline with the Node API to better separate source functionality from transform functionality (which is effectively done through thenormalize
logic currently)With all that context in mind, my core goal is to start a discussion about how we can move the Gatsby ecosystem forward to ensure it is the absolute best tool to modernize legacy CMS frameworks like WordPress. 😄
Excited for all your thoughts.
P.S. Documenting Node API helpers more would be so very, very helpful to future endeavors like this 😉