-
Notifications
You must be signed in to change notification settings - Fork 183
Restore changes to parse arrays of images #118
Conversation
This wasn't overriden but moved higher in the file. I don't get what your PR is supposed to add |
@alexandrebodin hi, this PR allows to use the publicURL field on arrays of images. Right now if I do something like this:
gatsby fails to build because there are no nodes for the images. What this PR does is the same that my last PR did, #90 it allows to query the localFile field when using the Multiple Media type in the strapi admin panel. Edit: the reason why I opened this PR is that if you check the commit that I linked you can see that it deleted the changes I made to src/normalize.js from my previous pull request Edit 2: while my solution does the job PR #112 is better and solves the need for using the localFile field, it only has a minor issue but I already commented to let the author know. If that issue gets fixed I hope that the PR gets merged because this is a critical issue for my team and the others that had my same problem. |
Ok, Thank you. I'll check this. The diff is kinda hard to read so will have to test this thouroughly :) |
@denisgoryaynov Can you fix the conflicts in yout PR ? |
@alexandrebodin yes, I can do it later today |
@denisgoryaynov is it possible to use Gatsby-image in combination with multiple files? |
@denisgoryaynov how is the conflict resolve going? Keep up the great work! |
@alexandrebodin I fixed the conflicts, sorry if it took me so long |
src/normalize.js
Outdated
} | ||
// If we have cached media data and it wasn't modified, reuse | ||
// previously created file node to not try to redownload | ||
if (cacheMediaData && item.updatedAt === cacheMediaData.updatedAt) { |
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.
Actually, this should be an option as the timestamps are configurable per model. (e.g by default on mongo it is camelcased createdAt / updatedAt
and on sql databases it would be created_at / updated_at
.)
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.
Oh I didn't know that, I just changed it because at some point in the code the variable was set as updatedAt but then inside that if the value being used was updated_at which was always undefined for me and I just though that it was an inconsistency. I can try to test it and fix it tomorrow.
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.
@alexandrebodin I fixed it with your suggestion but I have a question.
What I did is to create a new variable like this: const itemUpdatedAt = item.updatedAt || item.updated_at
, is there a better way to check what database is being used or this method should be fine?
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.
Hi, This should be fine for now. We will need to fetch model metadata to be more dynamic in the future though :) Will test this weekend se we can release next week ;)
HI @denisgoryaynov can you just fix the DCO check on this PR plz ? :D |
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.
Can you explain why you use localFile as a key here ? Can't we just have an array of images ?
Signed-off-by: denisgoryaynov <denis.gor27@gmail.com>
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com> Signed-off-by: denisgoryaynov <denis.gor27@gmail.com>
Signed-off-by: denisgoryaynov <denis.gor27@gmail.com>
@alexandrebodin I fixed all the issues. I used the localFile key because at the time I didn't know how to do it and that's what other plugins were using (for example gatsby-source-wordpress) and unfortunately I didn't really have much time to take a better look at it and see if it was possible to solve the issue without using the localFile key. |
Got ya branch working for a current project I'm working on using gatsby-image. Hope it gets pulled in, thanks for the great work! |
I have also check out this branch in my current project and it solves my problem with arrays of images. Thanks for the great work. |
@denisgoryaynov Is there a way to use your repository/branch into my Gatsby project with yarn instead of the standard gatsby-source-strapi package that is downloaded from npm? |
You can just yarn add the git directly but you need to fork it to your own and build the package. This is the src for the plugin so does not have the compiled JS that Gatsby is expecting. I forked the git, built the src and committed that and it works fine.
Like https://github.com/carlaiau/gatsby-source-strapi
|
Thanks a lot @carlaiau . This would allow me to continue with my project. |
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.
Hi @denisgoryaynov Thank you again fro your PR,
what I noticed is that using the localeFile key we can get the Strapi image fields (alternativeText, caption...) I feel like we should even do that with single images tbh. This would make the Schema more consistent. Waht do you think ?
@alexandrebodin that's a good idea, I recently updated to strapi beta 20 and didn't notice that these fields were missing from single images, I'll take a look a it! |
Signed-off-by: denisgoryaynov <denis.gor27@gmail.com>
@alexandrebodin I updated my code, it should be good now |
Thanks @denisgoryaynov ! Much appreciated :) |
package.json
Outdated
"peerDependencies": { | ||
"gatsby-source-filesystem": "^2.x" | ||
}, | ||
"pre-commit": [ |
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 the precommit it is handled by husky now
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 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.
@alexandrebodin @tonoli Sorry for the delay, I was on vacation. I pushed the updated code now
Signed-off-by: denisgoryaynov <denis.gor27@gmail.com>
@alexandrebodin @tonoli Hi, I fixed the conflict in fetch.js after the latest commit |
@denisgoryaynov thanks for your work! I have not tested your PR but does it address creating a local gatsby File for each of the strapi image formats (large, medium and thumbnail) or does it create a whole new field such as
Just curious how your PR implements the fix. |
@hashinteractive Hi, yes it does create a localFile field for every format What the code does is to iterate every field recursively and if it finds an image (I test for the "mime" field to detect an image as the original implementation) it generates a localFile node with publicURL and childImageSharp properties P.S. Thank you, when doing this screenshot I found out that there was a bug when generating images for formats. |
@denisgoryaynov thanks for your work and for the explanation. Hopefully we can get the PR merged soon 🙏 |
Signed-off-by: denisgoryaynov <denis.gor27@gmail.com>
abc88ea
to
4c522a3
Compare
@denisgoryaynov I pulled your fork and when I build it fails because AllStrapiWebsites isn't showing up. When I revert back to origin AllStrapiWebsites appears. Have you tested your latest changes on a vanilla Gatsby-Strapi environment? |
Will this pull request fix fetching alt text from single images? I would really love to see that merged soon. |
@MrChrisRodriguez Hi, sorry for the late response but I missed the notification. I tried by setting up a vanilla project using And here is what I added to my package.json: I forgot to update to build branch with the latest files from the master branch so that's maybe why you had issues, it should be ok now. @Bubiec yes it does generate alternativeText for single images, you can see it from the screenshot above |
Hi @denisgoryaynov. I refactored quite a lot of code and integrated changes to support what you have done. I released v1.0.0-alpha.0 with the latest changes. please try it out to validate things work for you so we can move release as latest ! |
Hi @alexandrebodin, thank you! I will try the new version as soon as I can! |
Hello 👋 How is it going with this PR? @denisgoryaynov |
Hi @DimaMiro the changes of this PR were integrated in the v1 alpha release |
Hi @alexandrebodin 👋 I've tried this change in alpha and it works correctly. Thank you 🙌 |
Hi, how is it going with PR? @denisgoryaynov @alexandrebodin I need this change in my projects. |
@visuvelu if you check the comments above you will see we made the fix in the alpha version but not many people have tester it so far so I'm holding off the release. You can use it as it fixes a lot of the current issues |
Worked great for me. Thanks a lot! |
Hi, We just released the v1.0.0 fixing including this requested changes :) |
It seems that the changes form my previous pull request were overwritten by this commit that implemented compatibility with Gatsby Cloud. This pull request is just to restore the files that allowed parsing arrays of images and query them like this