-
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
Process Contentful images inlined in markdown #5542
Process Contentful images inlined in markdown #5542
Conversation
Deploy preview for using-drupal ready! Built with commit ea3ff23 |
Deploy preview for gatsbygram ready! Built with commit ea3ff23 |
Any reviewer? |
backgroundColor: `white`, | ||
linkImagesToOriginal: true, | ||
showCaptions: false, | ||
pathPrefix, |
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.
linkImagesToOriginal, showCaptions and pathPrefix aren't really used anywhere? Or I'm missing something?
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.
for some reason my changes were not pushed to the branch 🙈
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.
Done
method: `GET`, | ||
url: `https:${node.url}`, // for some reason there is a './' prefix | ||
responseType: `stream`, | ||
}) |
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 think it would be good idea to implement some sort of caching mechanism so we don't have to redownload images everytime
sqip plugin implemented this locally - https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-transformer-sqip/src/extend-node-type.js#L229-L248 - maybe this can be turned into utility that could be moved to main contentful plugin and exported from it?
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 don't actually download the entire file I just get the metadata from the first bits in the stream and then destroy it
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've missed that, you are of course right. In any case we could cache metadata so we don't do same requests every build I think.
One way to do it is to pass cache
helper utility here https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-transformer-remark/src/extend-node-type.js#L181-L188 and use that here - similar to what sqip plugin is doing - https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-transformer-sqip/src/generate-sqip.js#L38-L76 (just note that cache
is not namespaced so, you would have to namespace used keys yourself.
If you are not sure how to use it just let me know - I can jump in and do this part.
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.
Hey @pieh That would be nice but I think the gatsby-transfromer-remark
is not passing the cache
function to it's plugins.
Does it make sense to add a PR that does that ?
const rawHtmlNodes = select(markdownAST, `html`) | ||
|
||
const generateImagesAndUpdateNode = async function(node, resolve) { | ||
// Ingonre if it is not contentful image |
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.
typo in "Ingonre" :)
node => | ||
new Promise(async (resolve, reject) => { | ||
// Ignore gifs as we can't process them, | ||
// svgs as they are already responsive by definition |
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.
are gifs and svgs actually ignored here? if so explanation that images.ctfassets.net
isn't used for those would be helpful
@pieh to be able to cache I added the ability to the |
@Khaledgarbaya Is this ready for another round of review? |
Hey @pieh yes this is ready for another round of review |
I tried it locally and I couldn't get placeholder images to show - should we actually download those (maybe change from w=40 to w=20 there) and inline it using And I think we would have to split this into 2 PRs - one is adding ---edit: |
Hey, @pieh that make sense. I will split this into 3 PRs |
@pieh this PR is ready for a review and once it's merged and released I will add the showcase page |
I updated minor stuff - formatting and failing test (which I'm not super happy how it looks but it works) and I think this is good to go! |
@Khaledgarbaya yeah, that's a lot nicer way for tests - do you want to add anything more here? If not I'll just fix formatting, rerun tests and merge this in! :) |
@pieh all good here nothing to add from my side |
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 very much @Khaledgarbaya !
* 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
Closes #1502
TODO :