TylerBarnes / gatsby-wordpress-inline-images

Fluid images for gatsby-source-wordpress inline images in post_content
57 stars 25 forks source link

Output post content is wrapped by gatsby image #31

Open garethgd opened 4 years ago

garethgd commented 4 years ago

Hi,

I really enjoy the effort that's been put into this plugin. I am just experiencing one small issue. When my inline images have been generated. For some of my posts, all of the content (h1, h2, p, span etc) is wrapped with the gatsby image wrapper (rather than just the images themselves).

<div class=" gatsby-image-wrapper" style="position:relative;overflow:hidden;max-width:100%" data-reactroot=""> My Post content </div>

This skews all my inline images and the images cover my post content. Is there perhaps a property I'm missing in the plugin configuration?

My config:


         {
            resolve: `gatsby-wordpress-inline-images`,
            options: {
              baseUrl: `www.fortniterandomizer.com`,
              protocol: `https`,
              useACF: true,
              wrapperStyle: ``,
              postTypes: ["post", "page"],
            }
          }
        ]
Jehu commented 4 years ago

Same Problem here. In our case it is a Custom AcfBlock with an image in it. All following blocks are rendered inside the gatsby-image-wrapper

Edit: oh we use gatsby-wordpress-experimental-inline-images by the way.

garethgd commented 4 years ago

Hi @Jehu,

This is far from a permanent solution but it works for me for building my articles at the moment.

I narrowed the issue down to a missing closing div for each gatsby-image-wrapper If you are using dangerouslySetInnerHTML for your post content you can create function to correct the markup:

parsePostContents = (contents) => {
     let replacedContent = contents.replace(/<\/noscript><\/div>/g, '</noscript></div></div>')
     return replacedContent;
  }

You can then use parsePostContents here:

<section
   className="post-content"
   dangerouslySetInnerHTML={{ __html: this.parsePostContents(post.content)}}
/>

AFAIK @TylerBarnes and the Gatsby team are current working on full fledged solution to Wordpress. So hopefully this ties you over for the moment

Jehu commented 4 years ago

@garethgd My colleague has copied the plugin to a local plugin and made some changes on the code. This resolves it for now. He may consider a pull request. Oh and wrapping the <img> in a <figure> is a must to get the closing tag problem solved.

TylerBarnes commented 4 years ago

Hey all, @garethgd is correct, we're currently working on a completely new WP source plugin that uses WPGraphQL and the functionality of this plugin will be built directly into the source plugin. All my attention has been focused there as the plan is to deprecate gatsby-source-wordpress@v3 and our usage of the REST api. There are too many unavoidable issues with using an untyped API. If anyone is interested in maintaining this package let me know!