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

Integration with gatsby-image #3

Closed
m4rcelofs opened this issue Sep 16, 2018 · 14 comments
Closed

Integration with gatsby-image #3

m4rcelofs opened this issue Sep 16, 2018 · 14 comments

Comments

@m4rcelofs
Copy link

While having the thumbnail urls is great, I'd love to use the full image as source for gatsby-image (specially because of lazy-load and avoiding company firewalls blocking instagram urls on visitors).

Apparently gatsby-source-contentful and gatsby-source-datocms already do something similar.

I'm new at gatsby and its plugins, but it seems conceivable. Would a PR for this be welcome? Any pointers on how I should get started?

@oorestisime
Copy link
Owner

Hello,

I ve already started working on this, i hope to have it ready soon. I am also new to gatsby :) so i wouldn't know how to give you any pointers.

@oorestisime
Copy link
Owner

So, i think i have working the gatsby-image part. I basically create the srcsets etc based on the available thumbnails and the original img (so no resizing etc) so that the lazy loading works.
I still need to download locally the images and cache them so that at the build the images are not fetched from instagram

oorestisime added a commit that referenced this issue Sep 18, 2018
* Provide srcSets from the available thumbnails and original image
* Provide src based on user options (defaults to original)

Contributes: #3
@oorestisime
Copy link
Owner

Hey so i ve refactored everything from this morning. you should be able to now use gatsby image and download locally everything. Please have a look at the readme for details and let me know if things work for you as expected!

@m4rcelofs
Copy link
Author

Just tried it with fluid images and works flawlessly, thanks!

@rchrdnsh
Copy link

rchrdnsh commented Jun 9, 2019

I can't seem to get this to work. This is what I'm doing:

allInstaNode(sort: { fields: [timestamp], order: DESC }) {
      edges {
        node {
          id
          likes
          comments
          mediaType
          preview
          original
          timestamp
          caption
          localFile {
            childImageSharp {
              fluid(maxWidth: 256) {
                ...GatsbyImageSharpFluid
              }
            }
          }
          thumbnails {
            src
            config_width
            config_height
          }
          dimensions {
            height
            width
          }
        }
      }
    }

then in my component:

<InstaGrid>
        {data.allInstaNode.edges.map(({ node }) => (
          <InstaPost key={node.id}>
            <InstaSpacer>
              <InstaLikes>❤️ {node.likes}</InstaLikes>
              <InstaComments>💬 {node.comments}</InstaComments>
              <InstaScrim />
              {/* <InstaImage src={node.original} /> */}
              <InstaImage src={node.localFile.childImageSharp.fixed} />
            </InstaSpacer>
          </InstaPost>
        ))}
      </InstaGrid>

If i just get the original or thumbnail it works, but if I switch over to localFile etc...the images don't work anymore...anything i should be doing differently?

@oorestisime
Copy link
Owner

hey there,
In your query you are asking for fluid but then on the gatsby image you seem to be passing fixed.

@rchrdnsh
Copy link

rchrdnsh commented Jun 9, 2019

apologies, yes, i tired both but copied from the wrong one. Neither fixed nor fluid seem to be working for me, but original does...but alas, without image optimization :-(

app screenshot with either fixed or fluid queries:

Screen Shot 2019-06-08 at 11 33 15 PM

@oorestisime
Copy link
Owner

maybe you have a repo i can look? not sure what InstaImage is for example.

@rchrdnsh
Copy link

rchrdnsh commented Jun 9, 2019

sure:

https://github.com/arrowgtp/alma

also, <InstaImage> is a styled component for the image itself, which looks like this:

const InstaImage = styled.img`
  grid-row: 1 / 9;
  grid-column: 1 / 9;
  margin: 0;
  padding: 0;
  border-radius: 16px;
  object-fit: cover;
  width: 100%;
  height: 100%;
  z-index: 0;
`

is is a child of a grid item, but otherwise everything about it's css is pretty normal.

Also, just to re-iterate, if I load up this instead:

<InstaImage src={node.original} />

instead of:

<InstaImage src={node.localFile.childImageSharp.fluid} />

the images load just fine...just no dope gatsby image processing...and lighthouse yelled at me for it :-(

@oorestisime
Copy link
Owner

So you are not using gatsby image, just plain image tag!
have you looked at the gatsby image documentation?

@rchrdnsh
Copy link

rchrdnsh commented Jun 9, 2019

I'm importing:

import Img from 'gatsby-image'

I think this is correct, but let me double check it really quick.

@oorestisime
Copy link
Owner

yeah but your styled-component is not using it! it is using styled.img should be styled(Img)

@rchrdnsh
Copy link

rchrdnsh commented Jun 9, 2019

welp, looks like i'm not so smart! 😬

k, that fixed it, along with changing src to fluid, which i totally do elsewhere, but completely kerplunkt that one!

Thank you very much for your expedient help!

@oorestisime
Copy link
Owner

no worries! happy to help!

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

No branches or pull requests

3 participants