-
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
feat(contentful): add traced SVGs to Contentful images #5659
Conversation
Deploy preview for using-drupal ready! Built with commit 7d6b311 |
Deploy preview for gatsbygram ready! Built with commit 7d6b311 |
BUT I am getting the same error on my local installation. The gif above I actually worked because I did not use the fragment, I put the required values there on my own. Any ideas why my Fragments are not found by Gatsby?
https://app.netlify.com/sites/using-contentful/deploys/5b112d828df894600842a8f4 |
It's caused by these lines I think: gatsby/packages/gatsby-source-contentful/src/gatsby-node.js Lines 214 to 217 in 31530b8
The fragments are copied from your local Gatsby install's So the above lines are copying the fragments into your project's |
Alright. So I'd say this is ready for review/release? <3 |
Nice! |
How about copying built fragments.js then? What's the reason for copying it from There is also issue of download images - right now this is duplicated in sqip plugin, and there is PR from @Khaledgarbaya ( https://github.com/gatsbyjs/gatsby/pull/5542/files/ba9cef15ee44be31c85c6f121fc2029bbe9b9c8f#diff-64f3938da48c0307f60ef3360a76d68fR49 ) that adds this in yet another place. Problem I have with this sqip and this PR have separate caches and It would be nice to abstract it, so this can be reused in all places I mentioned (not true blocker, but would be nice to solve it) |
Makes totally sense. Should be a seperate PR which maybe gets merged before this to fix deployment preview 🤔
I agree, we should have a generic function which all plugins use for this
Same here, maybe gatsby should define a folder where such files should be cached. Not all downloaded files need to end up in public/static. Maybe |
We do have createRemoteFileNode which handles downloads, caching but also creates file nodes which won't really work here - if this would be broken down so we could import just downloading and caching part this could be solution here |
So these are the Contentful image download duplicates:
I see two options:
Both should return a Gatsby file object since in many cases these structure is needed. Others use cases can just extract the values they need. What do you think? Related to #5542 |
I created #5698 which should get https://deploy-preview-5659--using-contentful.netlify.com/image-api/ deployed successfully after it was merged :) |
As Khaled pointed out in there - it doesn't actually download and save file, so we should skip it from discussion (my bad for bringing this up).
As I mentioned above there is createRemoteFileNode (used by some source plugins - like wordpress/drupal to download media library) - we could refactor it a bit so we could use just downloading and caching part of it. In situation like this we don't really want to create Gatsby File node because at this stage (doing work in resolver) schema is already created. It shouldn't break anything to just use it in its current form and extract path to downloaded file from it - it just would do some unnecessary work/overhead). I can implement it first in |
@pieh sounds wonderful! We might consider just adding a new flag like |
// Downloading small version of the image with same aspect ratio | ||
const assetWidth = maxWidth || width | ||
const assetHeight = maxHeight || height | ||
let aspectRatio = image.aspectRatio |
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.
I was testing this locally and image.aspectRatio
was never defined for me - had to use this:
let aspectRatio = image.file.details.image.height / image.file.details.image.width
what am I missing here?
Just posting progress update - I started working on using |
@@ -33,5 +33,8 @@ | |||
"build": "babel src --out-dir . --ignore __tests__", | |||
"prepublish": "cross-env NODE_ENV=production npm run build", | |||
"watch": "babel -w src --out-dir . --ignore __tests__" | |||
}, | |||
"optionalDependencies": { | |||
"gatsby-plugin-sharp": "^1.6.46" |
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.
If this is set as optional there should be some kind of check in code if it's available before using it. I think this should be just moved to dependencies
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.
Lets just move it, everybody working with images should have that one anyways.
My current thinking is to merge this almost as-is so switching to using |
Sounds good to me, Switching to Why would you not use |
54abaf1
to
c1c57e0
Compare
async function sqipSharp({ type, cache, getNodeAndSavePathDependency }) { | ||
async function sqipSharp({ type, cache, getNodeAndSavePathDependency, store }) { | ||
const program = store.getState().program | ||
const cacheDir = resolve(`${program.directory}/.cache/sqip/`) |
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.
Hint: This changes the cacheDir of SQIP to be aligned with the cached Contentful assets. Both of these do not need to be publicly available.
@pieh @m-allanson @KyleAMathews This is ready for review. IMHO the PR cleans up the code a lot and adds features while increasing readability :) |
This looks good - I have just 2 semi related issues:
|
c1c57e0
to
7d6b311
Compare
Done, I did split it up into two PRs. See #5859 |
I incremented the size by one pixel to ensure the user will see the traced SVG :) (In the other PR) Anything else? 🤝 |
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.
Thank you for keeping up with my comments and getting this across the finish line! ❤️
🎉 |
Awesome work! Sorry for being a n00b, but can someone please provide an example query to include an image sourced from Contentful using the traced image? I have only used imageSharp with a local file like below in the past.
Many thanks |
@nimaiwalsh Hey, changes from this PR weren't published yet. I will leave comment when they will go live. |
@pieh Awesome. Thanks. |
* master: (26 commits) Publish [feat] Extract internal plugin for automatically creating pages so we can reuse for other directories (#4490) fix(contentful): properly delete deleted entries and assets (#5756) Fix typo add Linda's post (#5817) [gatsby-source-contentful] Fix prepareJSONNode for array normalization (#5107) Process Contentful images inlined in markdown (#5542) feat(contentful): add traced SVGs to Contentful images (#5659) [SQIP] Add documentation (#5287) Add site to showcase (#5819) [gatsby-remark-copy-linked-files] Support reference-style images (#5818) Update docs for gatsby-plugin-catch-links (#5843) Added ⋅ representing a space to sub-list examples to reflect actual code (#5829) Adding tigerfacilityservices.com to showcase (#5855) fix schema type conflict reporter regressions (#5805) [gatsby-plugin-feed] Support nested output directory (#5820) Make cache available to the plugins (#5840) [gatsby-source-contentful] update data and jest snapshots (#5802) [gatsby-plugin-manifest] Replace all manifest.json with manifest.webmanifest in comments/docs (#5157) Update deploy-gatsby.md (#5800) ... # Conflicts: # docs/tutorial/part-one/index.md # examples/using-sqip/src/components/polaroid.js # packages/gatsby-image/README.md # packages/gatsby-image/package.json # packages/gatsby-plugin-catch-links/package.json # packages/gatsby-plugin-feed/package.json # packages/gatsby-plugin-manifest/package.json # packages/gatsby-plugin-page-creator/src/gatsby-node.js # packages/gatsby-remark-copy-linked-files/package.json # packages/gatsby-source-contentful/package.json # packages/gatsby-source-contentful/src/__tests__/__snapshots__/normalize.js.snap # packages/gatsby-source-contentful/src/extend-node-type.js # packages/gatsby-source-contentful/src/gatsby-node.js # packages/gatsby-source-contentful/src/normalize.js # packages/gatsby-transformer-remark/package.json # packages/gatsby-transformer-remark/src/__tests__/__snapshots__/gatsby-node.js.snap # packages/gatsby-transformer-sqip/package.json # packages/gatsby-transformer-sqip/src/extend-node-type.js # packages/gatsby/package.json # packages/gatsby/src/bootstrap/load-plugins/__tests__/__snapshots__/load-plugins.js.snap # packages/gatsby/src/bootstrap/load-plugins/load.js # www/src/data/sites.yml
Since Contentful is supported by the SQIP transformer, this now enables traced SVG previews for Contentful Assets :)